求助,为什么++写在里面就不行
查看原帖
求助,为什么++写在里面就不行
151672
Reee1e楼主2020/6/8 18:50
    p[++now]=point{c,d,now};
    p[++now]=point{a-1,d,now};
    p[++now]=point{c,b-1,now};
    p[++now]=point{a-1,b-1,now};
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define re register int
#define _ 0
#define DEBUG 1  // 调试开关
struct IO {
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
  char buf[MAXSIZE], *p1, *p2;
  char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
  IO() : p1(buf), p2(buf), pp(pbuf) {}
  ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }
#endif
  inline char gc() {
#if DEBUG  // 调试,可显示字符
    return getchar();
#endif
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
    return p1 == p2 ? ' ' : *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    register double tmp = 1;
    register bool sign = 0;
    x = 0;
    register char ch = gc();
    for (; !isdigit(ch); ch = gc())
      if (ch == '-') sign = 1;
    for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
      for (ch = gc(); isdigit(ch); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
  }
  inline void read(char *s) {
    register char ch = gc();
    for (; blank(ch); ch = gc())
      ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
  }
  inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
      ;
  }
  inline void push(const char &c) {
#if DEBUG  // 调试,可显示字符
    putchar(c);
#else
    if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
    *pp++ = c;
#endif
  }
  template <class T>
  inline void write(T x) {
    if (x < 0) x = -x, push('-');  // 负数输出
    static T sta[35];
    T top = 0;
    do {
      sta[top++] = x % 10, x /= 10;
    } while (x);
    while (top) push(sta[--top] + '0');
  }
  template <class T>
  inline void write(T x, char lastChar) {
    write(x), push(lastChar);
  }
} io;

const int N=5e5+10,L=1e7+5;

int ans[N<<2];


  int c[L];
  inline int lb(re x){return x&(-x);}
  inline void add(re x){
    x++;//同下!!!!!!!!!!!!!!!!!
    while(x<=L)
      c[x]+=1,x+=lb(x);
  }
  inline int sum(re x){
    x++;//树状数组下标要从1开始!!!!!!!!!!!!!
    re ans=0;
    while(x)
      ans+=c[x],x-=lb(x);
    return ans;
  }


struct tree{
  int x,y;
  bool operator<(const tree t)const{
    return x<t.x;
  }
}t[N];
struct point{
  int x,y,order;
  point(re x=0,re y=0,re order=0):x(x),y(y),order(order){}
  bool operator<(const point p)const{
    return x<p.x;
  }
}p[N<<2];

int main(){
	re m,n;
	io.read(n),io.read(m);
  for(re i=1;i<=n;i++){
    io.read(t[i].x),io.read(t[i].y);
  } 
  sort(t+1,t+n+1);
  re now=0;
  for(re i=1;i<=m;i++){
    //将询问拆成4个点,容斥输出(前缀和思想)
    //(a,b)为左下角
    //(c,d)为右上角
    re a,b,c,d;
    io.read(a),io.read(b),io.read(c),io.read(d);
    ///////////////
    //这里/////////
    ++now;
    p[now]=point{c,d,now};
    ++now;
    p[now]=point{a-1,d,now};
    ++now;
    p[now]=point{c,b-1,now};
    ++now;
    p[now]=point{a-1,b-1,now};
  }
  sort(p+1,p+now+1);
  re q=1;
  for(re i=1;i<=now;i++){
    while(t[q].x<=p[i].x&&q<=n)//一定要加上q<=n!!!
      add(t[q].y),q++;
    ans[p[i].order]+=sum(p[i].y);
    // if(p[i].y==1)putchar(':'),io.write(p[i].order,'*');
  }
  // printf("***%d %d %d %d***\n",p[1].order,p[2].order,p[3].order,p[4].order);
  for(re i=1;i<=now;i+=4){
    io.write(ans[i]-ans[i+1]-ans[i+2]+ans[i+3],'\n');
  }
	return ~~( 0 ^ _ ^ 0 );
}

把下面的代码注释标记部分换成上面的就不行了,为什么啊

评测记录1

评测记录2

2020/6/8 18:50
加载中...