#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
inline void out(long long x){if(x<0) putchar('-'),x=-x;if(x>9) out(x/10);putchar(x%10+'0');}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define task "EXAMINATION"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
const int N=100010;
int n,q;
ii a[N];
struct id{
int x,y,z,i;
}qry[N];
int ans[N];
vector<int> r;
int upp(int i,const vector<int>&v){
return lower_bound(all(v),i)-v.begin()+1;
}
struct fenwick{
vector<int> bit;
void add(int i){
if(!bit.size()) bit.resize(r.size());
for(;i;i-=i&-i) bit[i]++;
}
int que(int i){
if(!bit.size()) bit.resize(r.size());
int ret=0;
for(;i<=r.size();i+=i&-i) ret+=bit[i];
return ret;
}
}TT[N*3];
void add(int t){
int x,y; x=upp(a[t].fi,r), y=upp(a[t].se,r);
for(int i=x;i;i-=i&-i)
TT[i].add(y);
}
int que(int x,int y){
x=upp(x,r), y=upp(y,r);
int ret=0;
for(int i=x;i<=r.size();i+=i&-i)
ret+=TT[i].que(y);
return ret;
}
main()
{
//freopen(task".inp","r",stdin);
n=in,q=in;
forinc(i,1,n) a[i]={in,in};
sort(a+1,a+n+1,[](ii i,ii j){return i.fi+i.se>j.fi+j.se;});
forinc(i,1,q) qry[i]={in,in,in,i};
sort(qry+1,qry+q+1,[](id i,id j){return i.z>j.z;});
forinc(i,1,n) r.pb(a[i].fi),r.pb(a[i].se),r.pb(a[i].fi+a[i].se);
sort(all(r)); r.erase(unique(all(r)),r.end());
int j=1;
forinc(i,1,q){
while(j<=n && a[j].fi+a[j].se>=qry[i].z){
add(j++);
}
ans[qry[i].i]=que(qry[i].x,qry[i].y);
}
forinc(i,1,q){
cout<<ans[i]<<"\n";
}
}
Compilation message
examination.cpp: In member function 'int fenwick::que(int)':
examination.cpp:44:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;i<=r.size();i+=i&-i) ret+=bit[i];
~^~~~~~~~~~
examination.cpp: In function 'int que(int, int)':
examination.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=x;i<=r.size();i+=i&-i)
~^~~~~~~~~~
examination.cpp: At global scope:
examination.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
10 ms |
7424 KB |
Output is correct |
7 |
Correct |
210 ms |
201180 KB |
Output is correct |
8 |
Correct |
217 ms |
203256 KB |
Output is correct |
9 |
Correct |
189 ms |
204024 KB |
Output is correct |
10 |
Correct |
112 ms |
103544 KB |
Output is correct |
11 |
Incorrect |
12 ms |
8064 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1022 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1022 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
10 ms |
7424 KB |
Output is correct |
7 |
Correct |
210 ms |
201180 KB |
Output is correct |
8 |
Correct |
217 ms |
203256 KB |
Output is correct |
9 |
Correct |
189 ms |
204024 KB |
Output is correct |
10 |
Correct |
112 ms |
103544 KB |
Output is correct |
11 |
Incorrect |
12 ms |
8064 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |