Submission #997980

# Submission time Handle Problem Language Result Execution time Memory
997980 2024-06-13T07:26:47 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
482 ms 38360 KB
#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 2 ms 3428 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 2 ms 3420 KB Output is correct
4 Correct 1 ms 3416 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 13 ms 4568 KB Output is correct
8 Correct 10 ms 4464 KB Output is correct
9 Correct 10 ms 4568 KB Output is correct
10 Correct 10 ms 4568 KB Output is correct
11 Correct 10 ms 4508 KB Output is correct
12 Correct 8 ms 4128 KB Output is correct
13 Correct 10 ms 4384 KB Output is correct
14 Correct 9 ms 4384 KB Output is correct
15 Correct 9 ms 4308 KB Output is correct
16 Correct 10 ms 4328 KB Output is correct
17 Correct 12 ms 4412 KB Output is correct
18 Correct 7 ms 4128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 30004 KB Output is correct
2 Correct 367 ms 29852 KB Output is correct
3 Correct 369 ms 29348 KB Output is correct
4 Correct 297 ms 28124 KB Output is correct
5 Correct 357 ms 28212 KB Output is correct
6 Correct 224 ms 24956 KB Output is correct
7 Correct 325 ms 31504 KB Output is correct
8 Correct 342 ms 31292 KB Output is correct
9 Correct 299 ms 30260 KB Output is correct
10 Correct 295 ms 27036 KB Output is correct
11 Correct 281 ms 27316 KB Output is correct
12 Correct 212 ms 25156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 30004 KB Output is correct
2 Correct 367 ms 29852 KB Output is correct
3 Correct 369 ms 29348 KB Output is correct
4 Correct 297 ms 28124 KB Output is correct
5 Correct 357 ms 28212 KB Output is correct
6 Correct 224 ms 24956 KB Output is correct
7 Correct 325 ms 31504 KB Output is correct
8 Correct 342 ms 31292 KB Output is correct
9 Correct 299 ms 30260 KB Output is correct
10 Correct 295 ms 27036 KB Output is correct
11 Correct 281 ms 27316 KB Output is correct
12 Correct 212 ms 25156 KB Output is correct
13 Correct 402 ms 31124 KB Output is correct
14 Correct 411 ms 31524 KB Output is correct
15 Correct 388 ms 27696 KB Output is correct
16 Correct 360 ms 28480 KB Output is correct
17 Correct 361 ms 31712 KB Output is correct
18 Correct 222 ms 24552 KB Output is correct
19 Correct 406 ms 32308 KB Output is correct
20 Correct 404 ms 32520 KB Output is correct
21 Correct 411 ms 30848 KB Output is correct
22 Correct 291 ms 29876 KB Output is correct
23 Correct 288 ms 30600 KB Output is correct
24 Correct 203 ms 25428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3428 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 2 ms 3420 KB Output is correct
4 Correct 1 ms 3416 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 13 ms 4568 KB Output is correct
8 Correct 10 ms 4464 KB Output is correct
9 Correct 10 ms 4568 KB Output is correct
10 Correct 10 ms 4568 KB Output is correct
11 Correct 10 ms 4508 KB Output is correct
12 Correct 8 ms 4128 KB Output is correct
13 Correct 10 ms 4384 KB Output is correct
14 Correct 9 ms 4384 KB Output is correct
15 Correct 9 ms 4308 KB Output is correct
16 Correct 10 ms 4328 KB Output is correct
17 Correct 12 ms 4412 KB Output is correct
18 Correct 7 ms 4128 KB Output is correct
19 Correct 376 ms 30004 KB Output is correct
20 Correct 367 ms 29852 KB Output is correct
21 Correct 369 ms 29348 KB Output is correct
22 Correct 297 ms 28124 KB Output is correct
23 Correct 357 ms 28212 KB Output is correct
24 Correct 224 ms 24956 KB Output is correct
25 Correct 325 ms 31504 KB Output is correct
26 Correct 342 ms 31292 KB Output is correct
27 Correct 299 ms 30260 KB Output is correct
28 Correct 295 ms 27036 KB Output is correct
29 Correct 281 ms 27316 KB Output is correct
30 Correct 212 ms 25156 KB Output is correct
31 Correct 402 ms 31124 KB Output is correct
32 Correct 411 ms 31524 KB Output is correct
33 Correct 388 ms 27696 KB Output is correct
34 Correct 360 ms 28480 KB Output is correct
35 Correct 361 ms 31712 KB Output is correct
36 Correct 222 ms 24552 KB Output is correct
37 Correct 406 ms 32308 KB Output is correct
38 Correct 404 ms 32520 KB Output is correct
39 Correct 411 ms 30848 KB Output is correct
40 Correct 291 ms 29876 KB Output is correct
41 Correct 288 ms 30600 KB Output is correct
42 Correct 203 ms 25428 KB Output is correct
43 Correct 451 ms 37084 KB Output is correct
44 Correct 439 ms 35384 KB Output is correct
45 Correct 482 ms 37344 KB Output is correct
46 Correct 407 ms 37944 KB Output is correct
47 Correct 432 ms 35784 KB Output is correct
48 Correct 231 ms 26792 KB Output is correct
49 Correct 468 ms 37684 KB Output is correct
50 Correct 443 ms 37808 KB Output is correct
51 Correct 434 ms 36296 KB Output is correct
52 Correct 451 ms 38360 KB Output is correct
53 Correct 291 ms 30516 KB Output is correct