#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
const int SIZE=1<<10;
int pointer=SIZE;
char buffer[SIZE];
inline char readchar()
{
if(pointer==SIZE)
{
fread(buffer,1,SIZE,stdin);
pointer=0;
}
return buffer[pointer++];
}
#define getchar readchar
void read(int & x)
{
x=0;char c=getchar();
while(c<'0'||c>'9') c=getchar();
while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
}
inline void out(int x)
{
if(x>9) out(x/10);
putchar(x%10+'0');
}
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#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 onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
#define read2(a,b) read(a),read(b)
#define read3(a,b,c) read(a),read(b),read(c)
const int N=100010;
int n,m,ans[N];
vector<int> t[N],e,sv[N];
struct oo {int x,y,z,id;} a[N],q[N];
bool cmp(oo u,oo v) {return u.x>v.x;}
int v(int x) {return lower_bound(all(e),x)-e.begin()+1;}
int vz(int i,int x) {return lower_bound(all(sv[i]),x)-sv[i].begin()+1;}
void add(int i,int j)
{
i=v(i);
for(;i;i-=i&-i) t[i].pb(0),sv[i].pb(j);
}
void update(int i,int j)
{
i=v(i);
for(;i;i-=i&-i)
{
int _j=vz(i,j);
for(;_j;_j-=_j&-_j) t[i][_j]++;
}
}
int get(int i,int j)
{
int g=0;
i=v(i);
for(;i<=n;i+=i&-i)
{
int _j=vz(i,j);
for(;_j<t[i].size();_j+=_j&-_j) g+=t[i][_j];
}
return g;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("Examination.inp","r",stdin);
read2(n,m);
forinc(i,1,n)
{
read2(a[i].x,a[i].y),a[i].z=a[i].x+a[i].y;
e.pb(a[i].y);
}
sort(all(e));
forinc(i,1,m)
{
read3(q[i].x,q[i].y,q[i].z);
q[i].id=i;
}
forinc(i,1,n)
{
t[i].pb(0);
add(a[i].y,a[i].z);
}
forinc(i,1,n) sort(all(sv[i]));
sort(a+1,a+n+1,cmp);
sort(q+1,q+m+1,cmp);
int top=1;
forinc(i,1,m)
{
while(top<=n&&a[top].x>=q[i].x) update(a[top].y,a[top].z),top++;
ans[q[i].id]=get(q[i].y,q[i].z);
}
forinc(i,1,m) {out(ans[i]);putchar('\n');}
}
Compilation message
examination.cpp: In function 'int get(int, int)':
examination.cpp:71:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(;_j<t[i].size();_j+=_j&-_j) g+=t[i][_j];
~~^~~~~~~~~~~~
examination.cpp: In function 'char readchar()':
examination.cpp:14:14: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
fread(buffer,1,SIZE,stdin);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
4992 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
12 ms |
5632 KB |
Output is correct |
8 |
Correct |
12 ms |
5632 KB |
Output is correct |
9 |
Correct |
12 ms |
5632 KB |
Output is correct |
10 |
Correct |
12 ms |
5632 KB |
Output is correct |
11 |
Correct |
14 ms |
5632 KB |
Output is correct |
12 |
Correct |
10 ms |
5504 KB |
Output is correct |
13 |
Correct |
13 ms |
5632 KB |
Output is correct |
14 |
Correct |
13 ms |
5604 KB |
Output is correct |
15 |
Correct |
15 ms |
5632 KB |
Output is correct |
16 |
Correct |
12 ms |
5632 KB |
Output is correct |
17 |
Correct |
8 ms |
5376 KB |
Output is correct |
18 |
Correct |
7 ms |
5376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
655 ms |
22524 KB |
Output is correct |
2 |
Correct |
648 ms |
22772 KB |
Output is correct |
3 |
Correct |
602 ms |
22516 KB |
Output is correct |
4 |
Correct |
209 ms |
21720 KB |
Output is correct |
5 |
Correct |
582 ms |
22516 KB |
Output is correct |
6 |
Correct |
149 ms |
21620 KB |
Output is correct |
7 |
Correct |
599 ms |
22644 KB |
Output is correct |
8 |
Correct |
596 ms |
22576 KB |
Output is correct |
9 |
Correct |
510 ms |
22660 KB |
Output is correct |
10 |
Correct |
603 ms |
22516 KB |
Output is correct |
11 |
Correct |
97 ms |
13424 KB |
Output is correct |
12 |
Correct |
48 ms |
13300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
655 ms |
22524 KB |
Output is correct |
2 |
Correct |
648 ms |
22772 KB |
Output is correct |
3 |
Correct |
602 ms |
22516 KB |
Output is correct |
4 |
Correct |
209 ms |
21720 KB |
Output is correct |
5 |
Correct |
582 ms |
22516 KB |
Output is correct |
6 |
Correct |
149 ms |
21620 KB |
Output is correct |
7 |
Correct |
599 ms |
22644 KB |
Output is correct |
8 |
Correct |
596 ms |
22576 KB |
Output is correct |
9 |
Correct |
510 ms |
22660 KB |
Output is correct |
10 |
Correct |
603 ms |
22516 KB |
Output is correct |
11 |
Correct |
97 ms |
13424 KB |
Output is correct |
12 |
Correct |
48 ms |
13300 KB |
Output is correct |
13 |
Correct |
702 ms |
22424 KB |
Output is correct |
14 |
Correct |
691 ms |
22756 KB |
Output is correct |
15 |
Correct |
557 ms |
22872 KB |
Output is correct |
16 |
Correct |
304 ms |
21364 KB |
Output is correct |
17 |
Correct |
627 ms |
22516 KB |
Output is correct |
18 |
Correct |
155 ms |
21408 KB |
Output is correct |
19 |
Correct |
752 ms |
22656 KB |
Output is correct |
20 |
Correct |
620 ms |
22644 KB |
Output is correct |
21 |
Correct |
637 ms |
22500 KB |
Output is correct |
22 |
Correct |
588 ms |
22616 KB |
Output is correct |
23 |
Correct |
74 ms |
13424 KB |
Output is correct |
24 |
Correct |
48 ms |
13272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
4992 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
12 ms |
5632 KB |
Output is correct |
8 |
Correct |
12 ms |
5632 KB |
Output is correct |
9 |
Correct |
12 ms |
5632 KB |
Output is correct |
10 |
Correct |
12 ms |
5632 KB |
Output is correct |
11 |
Correct |
14 ms |
5632 KB |
Output is correct |
12 |
Correct |
10 ms |
5504 KB |
Output is correct |
13 |
Correct |
13 ms |
5632 KB |
Output is correct |
14 |
Correct |
13 ms |
5604 KB |
Output is correct |
15 |
Correct |
15 ms |
5632 KB |
Output is correct |
16 |
Correct |
12 ms |
5632 KB |
Output is correct |
17 |
Correct |
8 ms |
5376 KB |
Output is correct |
18 |
Correct |
7 ms |
5376 KB |
Output is correct |
19 |
Correct |
655 ms |
22524 KB |
Output is correct |
20 |
Correct |
648 ms |
22772 KB |
Output is correct |
21 |
Correct |
602 ms |
22516 KB |
Output is correct |
22 |
Correct |
209 ms |
21720 KB |
Output is correct |
23 |
Correct |
582 ms |
22516 KB |
Output is correct |
24 |
Correct |
149 ms |
21620 KB |
Output is correct |
25 |
Correct |
599 ms |
22644 KB |
Output is correct |
26 |
Correct |
596 ms |
22576 KB |
Output is correct |
27 |
Correct |
510 ms |
22660 KB |
Output is correct |
28 |
Correct |
603 ms |
22516 KB |
Output is correct |
29 |
Correct |
97 ms |
13424 KB |
Output is correct |
30 |
Correct |
48 ms |
13300 KB |
Output is correct |
31 |
Correct |
702 ms |
22424 KB |
Output is correct |
32 |
Correct |
691 ms |
22756 KB |
Output is correct |
33 |
Correct |
557 ms |
22872 KB |
Output is correct |
34 |
Correct |
304 ms |
21364 KB |
Output is correct |
35 |
Correct |
627 ms |
22516 KB |
Output is correct |
36 |
Correct |
155 ms |
21408 KB |
Output is correct |
37 |
Correct |
752 ms |
22656 KB |
Output is correct |
38 |
Correct |
620 ms |
22644 KB |
Output is correct |
39 |
Correct |
637 ms |
22500 KB |
Output is correct |
40 |
Correct |
588 ms |
22616 KB |
Output is correct |
41 |
Correct |
74 ms |
13424 KB |
Output is correct |
42 |
Correct |
48 ms |
13272 KB |
Output is correct |
43 |
Correct |
604 ms |
23256 KB |
Output is correct |
44 |
Correct |
652 ms |
23044 KB |
Output is correct |
45 |
Correct |
612 ms |
23280 KB |
Output is correct |
46 |
Correct |
281 ms |
22132 KB |
Output is correct |
47 |
Correct |
599 ms |
23284 KB |
Output is correct |
48 |
Correct |
155 ms |
21492 KB |
Output is correct |
49 |
Correct |
628 ms |
23184 KB |
Output is correct |
50 |
Correct |
684 ms |
23192 KB |
Output is correct |
51 |
Correct |
603 ms |
23252 KB |
Output is correct |
52 |
Correct |
631 ms |
23156 KB |
Output is correct |
53 |
Correct |
89 ms |
13428 KB |
Output is correct |