#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n,m;
tuple<int,int,int,int> a[N];
int ans[N],fw[N];
vector<int> tmp;
map<int,int> ma;
stack<int> st;
bool cmp(tuple<int,int,int,int> a,tuple<int,int,int,int> b){ return get<1>(a)<get<1>(b); }
void update(int idx,int val)
{
if(val==1) st.push(idx);
idx = ma[idx];
while(idx<N) fw[idx]+=val,idx+=(idx & -idx);
}
int read(int idx)
{
if(idx==INT_MAX) idx = N-1;
else idx = ma[idx];
int val = 0;
while(idx>0) val+=fw[idx],idx-=(idx & -idx);
return val;
}
void clear()
{
while(!st.empty()) update(st.top(),-1),st.pop();
}
void solve(int l,int r)
{
if(l==r) return;
int m = (l+r)/2;
solve(l,m),solve(m+1,r);
sort(a+l,a+m+1,cmp),sort(a+m+1,a+r+1,cmp);
int i = l,j = m+1;
while(i<=m+1 and j<=r)
{
int x = get<1>(a[i]),y = get<1>(a[j]),k = get<2>(a[i]),l = get<2>(a[j]),ix = get<3>(a[i]),iy = get<3>(a[j]);
if(x<=y){ if(!ix and i<=m) update(k,1); i++; }
else{ if(iy) ans[iy]+=read(l); j++; }
}
while(j<=r)
{
int l = get<2>(a[j]),iy = get<3>(a[j]);
ans[iy]+=read(l); j++;
}
clear();
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++)
{
int x,y;
cin >> x >> y;
x = -x,y = -y;
a[i] = {x,y,x+y,0};
tmp.push_back(x+y);
}
for(int i = 1;i <= m;i++)
{
int x,y,z;
cin >> x >> y >> z;
x = -x,y = -y,z = -z;
a[i+n] = {x,y,z,i};
tmp.push_back(z);
}
sort(tmp.begin(),tmp.end());
for(int i = 1;i <= tmp.size();i++) ma[tmp[i-1]] = i;
sort(a+1,a+n+m+1);
solve(1,n+m);
for(int i = 1;i <= m;i++) cout << ans[i] << '\n';
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:79:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1;i <= tmp.size();i++) ma[tmp[i-1]] = i;
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
21 ms |
1024 KB |
Output is correct |
8 |
Correct |
21 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1024 KB |
Output is correct |
10 |
Correct |
18 ms |
896 KB |
Output is correct |
11 |
Correct |
19 ms |
896 KB |
Output is correct |
12 |
Correct |
11 ms |
640 KB |
Output is correct |
13 |
Correct |
17 ms |
768 KB |
Output is correct |
14 |
Correct |
17 ms |
896 KB |
Output is correct |
15 |
Correct |
18 ms |
768 KB |
Output is correct |
16 |
Correct |
14 ms |
768 KB |
Output is correct |
17 |
Correct |
17 ms |
896 KB |
Output is correct |
18 |
Correct |
10 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
943 ms |
11956 KB |
Output is correct |
2 |
Correct |
934 ms |
11904 KB |
Output is correct |
3 |
Correct |
947 ms |
11900 KB |
Output is correct |
4 |
Correct |
605 ms |
10728 KB |
Output is correct |
5 |
Correct |
734 ms |
10592 KB |
Output is correct |
6 |
Correct |
276 ms |
6632 KB |
Output is correct |
7 |
Correct |
947 ms |
11888 KB |
Output is correct |
8 |
Correct |
910 ms |
11760 KB |
Output is correct |
9 |
Correct |
943 ms |
11760 KB |
Output is correct |
10 |
Correct |
593 ms |
10352 KB |
Output is correct |
11 |
Correct |
621 ms |
10620 KB |
Output is correct |
12 |
Correct |
210 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
943 ms |
11956 KB |
Output is correct |
2 |
Correct |
934 ms |
11904 KB |
Output is correct |
3 |
Correct |
947 ms |
11900 KB |
Output is correct |
4 |
Correct |
605 ms |
10728 KB |
Output is correct |
5 |
Correct |
734 ms |
10592 KB |
Output is correct |
6 |
Correct |
276 ms |
6632 KB |
Output is correct |
7 |
Correct |
947 ms |
11888 KB |
Output is correct |
8 |
Correct |
910 ms |
11760 KB |
Output is correct |
9 |
Correct |
943 ms |
11760 KB |
Output is correct |
10 |
Correct |
593 ms |
10352 KB |
Output is correct |
11 |
Correct |
621 ms |
10620 KB |
Output is correct |
12 |
Correct |
210 ms |
6124 KB |
Output is correct |
13 |
Correct |
1210 ms |
15340 KB |
Output is correct |
14 |
Correct |
1147 ms |
14576 KB |
Output is correct |
15 |
Correct |
948 ms |
11888 KB |
Output is correct |
16 |
Correct |
807 ms |
12376 KB |
Output is correct |
17 |
Correct |
936 ms |
12356 KB |
Output is correct |
18 |
Correct |
284 ms |
6892 KB |
Output is correct |
19 |
Correct |
1202 ms |
14956 KB |
Output is correct |
20 |
Correct |
1196 ms |
14576 KB |
Output is correct |
21 |
Correct |
1221 ms |
15120 KB |
Output is correct |
22 |
Correct |
601 ms |
10348 KB |
Output is correct |
23 |
Correct |
627 ms |
10360 KB |
Output is correct |
24 |
Correct |
219 ms |
6076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
21 ms |
1024 KB |
Output is correct |
8 |
Correct |
21 ms |
1024 KB |
Output is correct |
9 |
Correct |
21 ms |
1024 KB |
Output is correct |
10 |
Correct |
18 ms |
896 KB |
Output is correct |
11 |
Correct |
19 ms |
896 KB |
Output is correct |
12 |
Correct |
11 ms |
640 KB |
Output is correct |
13 |
Correct |
17 ms |
768 KB |
Output is correct |
14 |
Correct |
17 ms |
896 KB |
Output is correct |
15 |
Correct |
18 ms |
768 KB |
Output is correct |
16 |
Correct |
14 ms |
768 KB |
Output is correct |
17 |
Correct |
17 ms |
896 KB |
Output is correct |
18 |
Correct |
10 ms |
640 KB |
Output is correct |
19 |
Correct |
943 ms |
11956 KB |
Output is correct |
20 |
Correct |
934 ms |
11904 KB |
Output is correct |
21 |
Correct |
947 ms |
11900 KB |
Output is correct |
22 |
Correct |
605 ms |
10728 KB |
Output is correct |
23 |
Correct |
734 ms |
10592 KB |
Output is correct |
24 |
Correct |
276 ms |
6632 KB |
Output is correct |
25 |
Correct |
947 ms |
11888 KB |
Output is correct |
26 |
Correct |
910 ms |
11760 KB |
Output is correct |
27 |
Correct |
943 ms |
11760 KB |
Output is correct |
28 |
Correct |
593 ms |
10352 KB |
Output is correct |
29 |
Correct |
621 ms |
10620 KB |
Output is correct |
30 |
Correct |
210 ms |
6124 KB |
Output is correct |
31 |
Correct |
1210 ms |
15340 KB |
Output is correct |
32 |
Correct |
1147 ms |
14576 KB |
Output is correct |
33 |
Correct |
948 ms |
11888 KB |
Output is correct |
34 |
Correct |
807 ms |
12376 KB |
Output is correct |
35 |
Correct |
936 ms |
12356 KB |
Output is correct |
36 |
Correct |
284 ms |
6892 KB |
Output is correct |
37 |
Correct |
1202 ms |
14956 KB |
Output is correct |
38 |
Correct |
1196 ms |
14576 KB |
Output is correct |
39 |
Correct |
1221 ms |
15120 KB |
Output is correct |
40 |
Correct |
601 ms |
10348 KB |
Output is correct |
41 |
Correct |
627 ms |
10360 KB |
Output is correct |
42 |
Correct |
219 ms |
6076 KB |
Output is correct |
43 |
Correct |
1356 ms |
20500 KB |
Output is correct |
44 |
Correct |
1398 ms |
20588 KB |
Output is correct |
45 |
Correct |
1336 ms |
20488 KB |
Output is correct |
46 |
Correct |
997 ms |
19184 KB |
Output is correct |
47 |
Correct |
1208 ms |
19016 KB |
Output is correct |
48 |
Correct |
288 ms |
6508 KB |
Output is correct |
49 |
Correct |
1353 ms |
20696 KB |
Output is correct |
50 |
Correct |
1382 ms |
20364 KB |
Output is correct |
51 |
Correct |
1365 ms |
20540 KB |
Output is correct |
52 |
Correct |
956 ms |
18668 KB |
Output is correct |
53 |
Correct |
707 ms |
13036 KB |
Output is correct |