Submission #1048692

# Submission time Handle Problem Language Result Execution time Memory
1048692 2024-08-08T09:07:27 Z Minbaev Examination (JOI19_examination) C++17
100 / 100
668 ms 98696 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
 
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
 
using namespace std;
using namespace __gnu_pbds;
 
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define s second
#define int long long
#define ll long long
#define pii pair<int,int>
#define ar array
 
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
 
template<class T> using st = tree<T, null_type, less_equal<T>, 
rb_tree_tag, tree_order_statistics_node_update>;
 
const int inf = 1e17 + 7;
const int mod = 1e9 + 7;
const int N = 3e5 + 5;
const int md = 998244353;
 
int binpow(int a, int b){
	if(b == 0)return 1;
	if(b % 2 == 0){
		int c = binpow(a,b/2);
		return (c*c)%mod;
	}
	return (binpow(a,b-1)*a)%mod;
}
 
int divi(int a, int b){
	return (a*(binpow(b,mod-2)))%mod;
}
 
int n,m,k;
st<int>t[N];

void add(int i, int v){
	i = N - i - 1;
	for(;i<N;i+=(i&-i)) t[i].insert(v);
}

int get(int i, int v){
	int r = 0;
	 i = N - i - 1;
	for(;i>0;i-=(i&-i)) r += (t[i].size() - t[i].order_of_key(v));
	return r;
}

void solve(){
	
	cin >> n >> m;
	
	vector<pii>v(n);
	vector<int>a,b;
	vector<int>r,rt;
	for(int i = 0;i<n;i++){
		cin >> v[i].f >> v[i].s;
		r.pb(v[i].s);
		rt.pb(v[i].f+v[i].s);
	}
	
	sort(all(v));
	sort(all(r));
	sort(all(rt));
	for(int i = 0;i<n;i++){
		a.pb(v[i].s);
		b.pb(v[i].f+v[i].s);
	}
	
	vector<array<int,4>>q(m);
	for(int i = 0;i<m;i++){
		cin >> q[i][0] >> q[i][1] >> q[i][2];
		q[i][3] = i; 
	}
	vector<int>ans(m);
	sort(rall(q));
	
	int cur = n - 1;
	
	for(int i = 0;i<m;i++){
		while(cur >= 0 && v[cur].f >= q[i][0]){
			int x = lower_bound(all(r), a[cur]) - r.begin();
			int y = lower_bound(all(rt), b[cur]) - rt.begin();
			add(x, y);
			cur -= 1;
		}
		k = lower_bound(all(r), q[i][1]) - r.begin();
		int l = lower_bound(all(rt), q[i][2]) - rt.begin();
		ans[q[i][3]] = get(k, l);
		
	}
	
	for(auto to:ans)cout << to << "\n";
	
	
	

}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 0
10 10 0
60 60 0
0 100 0
*/
 signed main()
{
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt;
	while(tt--)solve();
 
}
 
# Verdict Execution time Memory Grader output
1 Correct 22 ms 28552 KB Output is correct
2 Correct 17 ms 28636 KB Output is correct
3 Correct 13 ms 28504 KB Output is correct
4 Correct 12 ms 28632 KB Output is correct
5 Correct 13 ms 28508 KB Output is correct
6 Correct 12 ms 28564 KB Output is correct
7 Correct 17 ms 30172 KB Output is correct
8 Correct 18 ms 30100 KB Output is correct
9 Correct 17 ms 30044 KB Output is correct
10 Correct 17 ms 29788 KB Output is correct
11 Correct 24 ms 30148 KB Output is correct
12 Correct 16 ms 30040 KB Output is correct
13 Correct 24 ms 30120 KB Output is correct
14 Correct 21 ms 30044 KB Output is correct
15 Correct 17 ms 30092 KB Output is correct
16 Correct 16 ms 30040 KB Output is correct
17 Correct 16 ms 29020 KB Output is correct
18 Correct 14 ms 29152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 94340 KB Output is correct
2 Correct 518 ms 94252 KB Output is correct
3 Correct 483 ms 94176 KB Output is correct
4 Correct 381 ms 98696 KB Output is correct
5 Correct 295 ms 93460 KB Output is correct
6 Correct 253 ms 85484 KB Output is correct
7 Correct 544 ms 94300 KB Output is correct
8 Correct 559 ms 94212 KB Output is correct
9 Correct 517 ms 94116 KB Output is correct
10 Correct 233 ms 93440 KB Output is correct
11 Correct 82 ms 45548 KB Output is correct
12 Correct 112 ms 44520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 94340 KB Output is correct
2 Correct 518 ms 94252 KB Output is correct
3 Correct 483 ms 94176 KB Output is correct
4 Correct 381 ms 98696 KB Output is correct
5 Correct 295 ms 93460 KB Output is correct
6 Correct 253 ms 85484 KB Output is correct
7 Correct 544 ms 94300 KB Output is correct
8 Correct 559 ms 94212 KB Output is correct
9 Correct 517 ms 94116 KB Output is correct
10 Correct 233 ms 93440 KB Output is correct
11 Correct 82 ms 45548 KB Output is correct
12 Correct 112 ms 44520 KB Output is correct
13 Correct 627 ms 94572 KB Output is correct
14 Correct 591 ms 94636 KB Output is correct
15 Correct 575 ms 94256 KB Output is correct
16 Correct 425 ms 94440 KB Output is correct
17 Correct 358 ms 93960 KB Output is correct
18 Correct 241 ms 89832 KB Output is correct
19 Correct 642 ms 94812 KB Output is correct
20 Correct 588 ms 94696 KB Output is correct
21 Correct 668 ms 94756 KB Output is correct
22 Correct 256 ms 93416 KB Output is correct
23 Correct 81 ms 45548 KB Output is correct
24 Correct 96 ms 44484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 28552 KB Output is correct
2 Correct 17 ms 28636 KB Output is correct
3 Correct 13 ms 28504 KB Output is correct
4 Correct 12 ms 28632 KB Output is correct
5 Correct 13 ms 28508 KB Output is correct
6 Correct 12 ms 28564 KB Output is correct
7 Correct 17 ms 30172 KB Output is correct
8 Correct 18 ms 30100 KB Output is correct
9 Correct 17 ms 30044 KB Output is correct
10 Correct 17 ms 29788 KB Output is correct
11 Correct 24 ms 30148 KB Output is correct
12 Correct 16 ms 30040 KB Output is correct
13 Correct 24 ms 30120 KB Output is correct
14 Correct 21 ms 30044 KB Output is correct
15 Correct 17 ms 30092 KB Output is correct
16 Correct 16 ms 30040 KB Output is correct
17 Correct 16 ms 29020 KB Output is correct
18 Correct 14 ms 29152 KB Output is correct
19 Correct 558 ms 94340 KB Output is correct
20 Correct 518 ms 94252 KB Output is correct
21 Correct 483 ms 94176 KB Output is correct
22 Correct 381 ms 98696 KB Output is correct
23 Correct 295 ms 93460 KB Output is correct
24 Correct 253 ms 85484 KB Output is correct
25 Correct 544 ms 94300 KB Output is correct
26 Correct 559 ms 94212 KB Output is correct
27 Correct 517 ms 94116 KB Output is correct
28 Correct 233 ms 93440 KB Output is correct
29 Correct 82 ms 45548 KB Output is correct
30 Correct 112 ms 44520 KB Output is correct
31 Correct 627 ms 94572 KB Output is correct
32 Correct 591 ms 94636 KB Output is correct
33 Correct 575 ms 94256 KB Output is correct
34 Correct 425 ms 94440 KB Output is correct
35 Correct 358 ms 93960 KB Output is correct
36 Correct 241 ms 89832 KB Output is correct
37 Correct 642 ms 94812 KB Output is correct
38 Correct 588 ms 94696 KB Output is correct
39 Correct 668 ms 94756 KB Output is correct
40 Correct 256 ms 93416 KB Output is correct
41 Correct 81 ms 45548 KB Output is correct
42 Correct 96 ms 44484 KB Output is correct
43 Correct 574 ms 96724 KB Output is correct
44 Correct 629 ms 96744 KB Output is correct
45 Correct 563 ms 96308 KB Output is correct
46 Correct 333 ms 88292 KB Output is correct
47 Correct 308 ms 95068 KB Output is correct
48 Correct 277 ms 88036 KB Output is correct
49 Correct 585 ms 96484 KB Output is correct
50 Correct 537 ms 96452 KB Output is correct
51 Correct 628 ms 96428 KB Output is correct
52 Correct 283 ms 94952 KB Output is correct
53 Correct 113 ms 46564 KB Output is correct