#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define pb push_back
#define eb emplace_back
#define pu push
#define ins insert
#define lowbit(x) x&-x
#define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff(x,a,b,c) for (auto x=a;x<=b;x+=c)
#define fd(x,a,b,c) for (auto x=a;x>=b;x-=c)
#define int ll
using namespace std;
const int N = 2e5+5;
const int mod = 1e9+7;
int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;}
map<int,int> cnt;
vector<array<int,4>> s;
int n,q;
int ans[N];
bool cmp(array<int,4> a,array<int,4> b)
{
return a[0]>b[0] || (a[0]==b[0] && a[3]<b[3]);
}
struct bintree{
vector<int> st;
vector<int> lazy;
void init()
{
st.resize(N,0); lazy.resize(N,0);
}
void update(int id,int val)
{
while (id<=cnt.size())
{
if (lazy[id]!=val) lazy[id] = val,st[id] = 0;
st[id]++;
id += lowbit(id);
}
}
int sum (int id,int x)
{
int ans = 0;
while (id>0)
{
if (lazy[id]!=x) lazy[id] = x,st[id] = 0;
ans+=st[id]; id-=lowbit(id);
}
return ans;
}
} bit;
void cdq(int id,int l,int r)
{
if (l==r) return;
int mid = l+(r-l)/2;
cdq(id*2,l,mid); cdq(id*2+1,mid+1,r);
int i = l,j = mid+1;
vector<array<int,4>> a;
while (i<=mid && j<=r)
{
if (s[i][1]>=s[j][1])
{
if (s[i][3]==-1) bit.update(cnt.size()-s[i][2],id);
a.pb(s[i]); i++;
} else
{
if (s[j][3]!=-1) ans[s[j][3]]+=bit.sum(cnt.size()-s[j][2],id);
a.pb(s[j]); j++;
}
}
while (i<=mid) a.pb(s[i]),i++;
while (j<=r)
{
if (s[j][3]!=-1) ans[s[j][3]]+=bit.sum(cnt.size()-s[j][2],id);
a.pb(s[j]); j++;
}
for (int i=l;i<=r;i++) swap(s[i],a[i-l]);
}
void solve()
{
bit.init();
cin>>n>>q;
for (int i=0;i<n;i++)
{
int x,y; cin>>x>>y;
s.pb({x,y,x+y,-1});
cnt[x+y]++;
}
for (int i=0;i<q;i++)
{
int x,y,z; cin>>x>>y>>z;
s.pb({x,y,z,i});
cnt[z]++;
}
sort(s.begin(),s.end(),cmp);
int idx = 0;
for (auto &[a,b] : cnt) b = idx++;
for (auto &[a,b,c,d] : s) c = cnt[c];
cdq(1,0,s.size()-1);
for (int i=0;i<q;i++) cout<<ans[i]<<endl;
}
signed main()
{
bruh
int t = 1;
//cin>>t;
while (t--)
{
solve();
cout<<"\n";
}
}
Compilation message
examination.cpp: In member function 'void bintree::update(long long int, long long int)':
examination.cpp:41:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | while (id<=cnt.size())
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
3 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
10 ms |
4496 KB |
Output is correct |
8 |
Correct |
10 ms |
4568 KB |
Output is correct |
9 |
Correct |
10 ms |
4428 KB |
Output is correct |
10 |
Correct |
10 ms |
4636 KB |
Output is correct |
11 |
Correct |
10 ms |
4568 KB |
Output is correct |
12 |
Correct |
8 ms |
4128 KB |
Output is correct |
13 |
Correct |
9 ms |
4312 KB |
Output is correct |
14 |
Correct |
9 ms |
4376 KB |
Output is correct |
15 |
Correct |
10 ms |
4348 KB |
Output is correct |
16 |
Correct |
8 ms |
4384 KB |
Output is correct |
17 |
Correct |
11 ms |
4568 KB |
Output is correct |
18 |
Correct |
7 ms |
4128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
29908 KB |
Output is correct |
2 |
Correct |
329 ms |
30916 KB |
Output is correct |
3 |
Correct |
323 ms |
29964 KB |
Output is correct |
4 |
Correct |
304 ms |
27548 KB |
Output is correct |
5 |
Correct |
366 ms |
29300 KB |
Output is correct |
6 |
Correct |
215 ms |
23872 KB |
Output is correct |
7 |
Correct |
335 ms |
29556 KB |
Output is correct |
8 |
Correct |
312 ms |
28980 KB |
Output is correct |
9 |
Correct |
371 ms |
30520 KB |
Output is correct |
10 |
Correct |
280 ms |
28056 KB |
Output is correct |
11 |
Correct |
275 ms |
27192 KB |
Output is correct |
12 |
Correct |
199 ms |
23172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
29908 KB |
Output is correct |
2 |
Correct |
329 ms |
30916 KB |
Output is correct |
3 |
Correct |
323 ms |
29964 KB |
Output is correct |
4 |
Correct |
304 ms |
27548 KB |
Output is correct |
5 |
Correct |
366 ms |
29300 KB |
Output is correct |
6 |
Correct |
215 ms |
23872 KB |
Output is correct |
7 |
Correct |
335 ms |
29556 KB |
Output is correct |
8 |
Correct |
312 ms |
28980 KB |
Output is correct |
9 |
Correct |
371 ms |
30520 KB |
Output is correct |
10 |
Correct |
280 ms |
28056 KB |
Output is correct |
11 |
Correct |
275 ms |
27192 KB |
Output is correct |
12 |
Correct |
199 ms |
23172 KB |
Output is correct |
13 |
Correct |
424 ms |
31300 KB |
Output is correct |
14 |
Correct |
425 ms |
30004 KB |
Output is correct |
15 |
Correct |
326 ms |
28964 KB |
Output is correct |
16 |
Correct |
351 ms |
31804 KB |
Output is correct |
17 |
Correct |
363 ms |
29596 KB |
Output is correct |
18 |
Correct |
223 ms |
24716 KB |
Output is correct |
19 |
Correct |
390 ms |
32088 KB |
Output is correct |
20 |
Correct |
399 ms |
32568 KB |
Output is correct |
21 |
Correct |
384 ms |
30788 KB |
Output is correct |
22 |
Correct |
292 ms |
28984 KB |
Output is correct |
23 |
Correct |
274 ms |
29400 KB |
Output is correct |
24 |
Correct |
203 ms |
23876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
3 ms |
3420 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3420 KB |
Output is correct |
7 |
Correct |
10 ms |
4496 KB |
Output is correct |
8 |
Correct |
10 ms |
4568 KB |
Output is correct |
9 |
Correct |
10 ms |
4428 KB |
Output is correct |
10 |
Correct |
10 ms |
4636 KB |
Output is correct |
11 |
Correct |
10 ms |
4568 KB |
Output is correct |
12 |
Correct |
8 ms |
4128 KB |
Output is correct |
13 |
Correct |
9 ms |
4312 KB |
Output is correct |
14 |
Correct |
9 ms |
4376 KB |
Output is correct |
15 |
Correct |
10 ms |
4348 KB |
Output is correct |
16 |
Correct |
8 ms |
4384 KB |
Output is correct |
17 |
Correct |
11 ms |
4568 KB |
Output is correct |
18 |
Correct |
7 ms |
4128 KB |
Output is correct |
19 |
Correct |
327 ms |
29908 KB |
Output is correct |
20 |
Correct |
329 ms |
30916 KB |
Output is correct |
21 |
Correct |
323 ms |
29964 KB |
Output is correct |
22 |
Correct |
304 ms |
27548 KB |
Output is correct |
23 |
Correct |
366 ms |
29300 KB |
Output is correct |
24 |
Correct |
215 ms |
23872 KB |
Output is correct |
25 |
Correct |
335 ms |
29556 KB |
Output is correct |
26 |
Correct |
312 ms |
28980 KB |
Output is correct |
27 |
Correct |
371 ms |
30520 KB |
Output is correct |
28 |
Correct |
280 ms |
28056 KB |
Output is correct |
29 |
Correct |
275 ms |
27192 KB |
Output is correct |
30 |
Correct |
199 ms |
23172 KB |
Output is correct |
31 |
Correct |
424 ms |
31300 KB |
Output is correct |
32 |
Correct |
425 ms |
30004 KB |
Output is correct |
33 |
Correct |
326 ms |
28964 KB |
Output is correct |
34 |
Correct |
351 ms |
31804 KB |
Output is correct |
35 |
Correct |
363 ms |
29596 KB |
Output is correct |
36 |
Correct |
223 ms |
24716 KB |
Output is correct |
37 |
Correct |
390 ms |
32088 KB |
Output is correct |
38 |
Correct |
399 ms |
32568 KB |
Output is correct |
39 |
Correct |
384 ms |
30788 KB |
Output is correct |
40 |
Correct |
292 ms |
28984 KB |
Output is correct |
41 |
Correct |
274 ms |
29400 KB |
Output is correct |
42 |
Correct |
203 ms |
23876 KB |
Output is correct |
43 |
Correct |
448 ms |
39180 KB |
Output is correct |
44 |
Correct |
475 ms |
38844 KB |
Output is correct |
45 |
Correct |
498 ms |
35632 KB |
Output is correct |
46 |
Correct |
399 ms |
35464 KB |
Output is correct |
47 |
Correct |
426 ms |
36032 KB |
Output is correct |
48 |
Correct |
232 ms |
25048 KB |
Output is correct |
49 |
Correct |
440 ms |
35464 KB |
Output is correct |
50 |
Correct |
444 ms |
37944 KB |
Output is correct |
51 |
Correct |
446 ms |
36704 KB |
Output is correct |
52 |
Correct |
410 ms |
37132 KB |
Output is correct |
53 |
Correct |
294 ms |
32732 KB |
Output is correct |