답안 #444116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444116 2021-07-13T06:26:31 Z minhcool Examination (JOI19_examination) C++17
43 / 100
3000 ms 23676 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define hash hashy
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 2e5 + 5, block = 900;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, q;
 
unordered_map<int, int> uomp;
vector<int> vc;
 
iii queries[N];
ii students1[N], students2[N];
 
vector<int> srt[N/block];
 
int bit[N];
bool in[N];
 
int answer[N];
int counter = 0;
 
void upd(int pos, int val){
	counter++;
	for(; pos <= n + q; pos += pos & -pos) bit[pos] += val;
}
 
int get(int pos){
	int ans = 0;
	for(; pos; pos -= pos & -pos) ans += bit[pos];
	return ans;
}
 
bool cmp(int a, int b){
	return (queries[a].fi.fi > queries[b].fi.fi);
}
 
void process(){
	cin >> n >> q;
	vector<int> vc;
	for(int i = 1; i <= n; i++){
		cin >> students1[i].fi >> students1[i].se;
		vc.pb(students1[i].se);
		students2[i] = {students1[i].fi + students1[i].se, i};
	}
	//if(n == 100000 && q == 100000 && students1[i].fi == 92665) return;
	sort(students2 + 1, students2 + n + 1);
	for(int i = 1; i <= q; i++){
		cin >> queries[i].fi.fi >> queries[i].fi.se >> queries[i].se;
		vc.pb(queries[i].fi.se);
		int pos = lower_bound(students2 + 1, students2 + n + 1, make_pair(queries[i].se, 0)) - students2;
		srt[pos / block].pb(i);
	}
	sort(vc.begin(), vc.end());
	vc.resize(unique(vc.begin(), vc.end()) - vc.begin());
	for(int i = 0; i < vc.size(); i++) uomp[vc[i]] = i + 1;
	set<ii> se;
	for(int i = n/block + 2; i >= 0; i--){// l = (i * block), r = (i + 1) * block - 1
		//cout << i << "\n";
		stack<ii> que;
		for(auto it : se) que.push(it);
		sort(srt[i].begin(), srt[i].end(), cmp);
		for(int j = 1; j <= n + q; j++) bit[j] = 0;
		for(int j = 1; j <= n; j++) in[j] = 0; 
		int lst = min(n + 1, (i + 1) * block);
		vector<ii> vc1;
		for(int j = max(1, i * block); j < min(n + 1, (i + 1) * block); j++){
			int tmp = students2[j].se;
			//if(!tmp) cout << j << " " << tmp << "\n";
			vc1.pb({students1[tmp].fi, tmp});
		}
		sort(vc1.begin(), vc1.end());
		for(auto it : srt[i]){
			//cout << it << " " << i << "\n";
				while(1){
					if(!que.size()) break;
					ii temp = que.top();
					//int x = que.top().fi;
					if(temp.fi < queries[it].fi.fi) break;
					//cout << x << " " << que.size() << "\n";
					in[temp.se] = 1;
					upd(uomp[students1[temp.se].se], 1);
					que.pop();
				}
			int temp = lower_bound(students2 + 1, students2 + n + 1, make_pair(queries[it].se, 0)) - students2;
			//cout << it << " " << temp << "\n";
			//cout << lst << " " << temp << " " << queries[it].se << "\n";
			//continue;
			for(int j = lst; j < temp; j++){
				if(in[students2[j].se]){
					in[students2[j].se] = 0;
					upd(uomp[students1[students2[j].se].se], -1);
				}
			} 
			for(int j = temp; j < lst; j++){
				if(students1[students2[j].se].fi >= queries[it].fi.fi && !in[students2[j].se]){
					in[students2[j].se] = 1;
					upd(uomp[students1[students2[j].se].se], 1);
				}
			}
			lst = temp;
			while(1){
				if(!vc1.size()) break;
				if(vc1.back().fi < queries[it].fi.fi) break;
				int ind = vc1.back().se;
				if(!in[ind] && students1[ind].fi + students1[ind].se >= queries[it].se){
					in[ind] = 1;
					//assert(ind);
					upd(uomp[students1[ind].se], 1);
				}
				vc1.pop_back();
				//cout << vc1.size() << "\n";
			}
			answer[it] = get(n + q) - get(uomp[queries[it].fi.se] - 1);
		}
		for(int j = i * block; j < min(n + 1, (i + 1) * block); j++){
			int tmp = students2[j].se;
			//cout << j << " " << tmp << "\n";
			se.insert({students1[tmp].fi, tmp});
		}
	}
	//cout << counter << "\n";
	//cout << (double)clock() / CLOCKS_PER_SEC;
	for(int i = 1; i <= q; i++) cout << answer[i] << "\n";
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	process();
}

Compilation message

examination.cpp:20:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   20 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
examination.cpp: In function 'void process()':
examination.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i = 0; i < vc.size(); i++) uomp[vc[i]] = i + 1;
      |                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 27 ms 880 KB Output is correct
8 Correct 26 ms 876 KB Output is correct
9 Correct 34 ms 888 KB Output is correct
10 Correct 23 ms 588 KB Output is correct
11 Correct 30 ms 844 KB Output is correct
12 Correct 19 ms 672 KB Output is correct
13 Correct 6 ms 844 KB Output is correct
14 Correct 6 ms 964 KB Output is correct
15 Correct 6 ms 972 KB Output is correct
16 Correct 5 ms 952 KB Output is correct
17 Correct 19 ms 588 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 15668 KB Output is correct
2 Correct 397 ms 15644 KB Output is correct
3 Correct 384 ms 15560 KB Output is correct
4 Correct 212 ms 11556 KB Output is correct
5 Correct 387 ms 15604 KB Output is correct
6 Correct 278 ms 11620 KB Output is correct
7 Correct 371 ms 15640 KB Output is correct
8 Correct 417 ms 14396 KB Output is correct
9 Correct 369 ms 14460 KB Output is correct
10 Correct 361 ms 15520 KB Output is correct
11 Correct 203 ms 11324 KB Output is correct
12 Correct 181 ms 11288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 15668 KB Output is correct
2 Correct 397 ms 15644 KB Output is correct
3 Correct 384 ms 15560 KB Output is correct
4 Correct 212 ms 11556 KB Output is correct
5 Correct 387 ms 15604 KB Output is correct
6 Correct 278 ms 11620 KB Output is correct
7 Correct 371 ms 15640 KB Output is correct
8 Correct 417 ms 14396 KB Output is correct
9 Correct 369 ms 14460 KB Output is correct
10 Correct 361 ms 15520 KB Output is correct
11 Correct 203 ms 11324 KB Output is correct
12 Correct 181 ms 11288 KB Output is correct
13 Correct 2439 ms 15792 KB Output is correct
14 Correct 1778 ms 15888 KB Output is correct
15 Correct 409 ms 15664 KB Output is correct
16 Correct 1401 ms 11648 KB Output is correct
17 Correct 1986 ms 15772 KB Output is correct
18 Correct 328 ms 11728 KB Output is correct
19 Correct 2514 ms 16040 KB Output is correct
20 Correct 2229 ms 15880 KB Output is correct
21 Correct 2839 ms 14920 KB Output is correct
22 Correct 355 ms 17228 KB Output is correct
23 Correct 204 ms 13164 KB Output is correct
24 Correct 209 ms 12204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 27 ms 880 KB Output is correct
8 Correct 26 ms 876 KB Output is correct
9 Correct 34 ms 888 KB Output is correct
10 Correct 23 ms 588 KB Output is correct
11 Correct 30 ms 844 KB Output is correct
12 Correct 19 ms 672 KB Output is correct
13 Correct 6 ms 844 KB Output is correct
14 Correct 6 ms 964 KB Output is correct
15 Correct 6 ms 972 KB Output is correct
16 Correct 5 ms 952 KB Output is correct
17 Correct 19 ms 588 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
19 Correct 378 ms 15668 KB Output is correct
20 Correct 397 ms 15644 KB Output is correct
21 Correct 384 ms 15560 KB Output is correct
22 Correct 212 ms 11556 KB Output is correct
23 Correct 387 ms 15604 KB Output is correct
24 Correct 278 ms 11620 KB Output is correct
25 Correct 371 ms 15640 KB Output is correct
26 Correct 417 ms 14396 KB Output is correct
27 Correct 369 ms 14460 KB Output is correct
28 Correct 361 ms 15520 KB Output is correct
29 Correct 203 ms 11324 KB Output is correct
30 Correct 181 ms 11288 KB Output is correct
31 Correct 2439 ms 15792 KB Output is correct
32 Correct 1778 ms 15888 KB Output is correct
33 Correct 409 ms 15664 KB Output is correct
34 Correct 1401 ms 11648 KB Output is correct
35 Correct 1986 ms 15772 KB Output is correct
36 Correct 328 ms 11728 KB Output is correct
37 Correct 2514 ms 16040 KB Output is correct
38 Correct 2229 ms 15880 KB Output is correct
39 Correct 2839 ms 14920 KB Output is correct
40 Correct 355 ms 17228 KB Output is correct
41 Correct 204 ms 13164 KB Output is correct
42 Correct 209 ms 12204 KB Output is correct
43 Execution timed out 3065 ms 23676 KB Time limit exceeded
44 Halted 0 ms 0 KB -