답안 #998002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998002 2024-06-13T07:38:35 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
1031 ms 79844 KB
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     //
//         Nhan qua khong no chung ta thu gi          //
//                 Vay nen dung oan han               //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     //
//                                                    //    
//                       _oo0oo_                      //
//                      o8888888o                     //
//                      88" . "88                     //					  
//                      (| -_- |)                     //
//                      0\  =  /0                     //
//                    ___/`---'\___                   //
//                  .' \\|     |// '.                 //
//                 / \\|||  :  |||// \                //  			  
//                / _||||| -:- |||||- \               // 			  
//               |   | \\\  -  /// |   |              //			  
//               | \_|  ''\---/''  |_/ |              //			  
//               \  .-\__  '-'  ___/-. /              //			  
//             ___'. .'  /--.--\  `. .'___            //			  
//          ."" '<  `.___\_<|>_/___.' >' "".          //  		  
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |        //		  
//         \  \ `_.   \_ __\ /__ _/   .-` /  /        //    	  
//     =====`-.____`.___ \_____/___.-`___.-'=====     //     
//                       `=---='                      //
//                                                    //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     //
//   Duc Phat noi day phu ho Code con chay khong Bug  //
//                 Nam mo a di da phat                //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     //

#include<bits/stdc++.h>
#ifdef LOCAL
#include "D:\debug.h"
#else
#define cebug(...) "Orz_chUoNgnn"
#endif

using namespace std;

#define fi first 
#define se second
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vll vector<ll>
#define vii vector<ii>
#define cd complex<double>
const ll mod = 1e9 + 7;
const ll INF = 1e18L + 5;
const double PI = acos(-1);
const int block = 320;
const int N = 1e6;
int tc, tt = 1;

struct student {
	ll a, b, c;
	ll in, q;
} a[N + 5];
#define vi vector<student> 
int n, q;
vector<int> f;
map<int, int> pos;
ll ans[N + 5];
struct fenwick_tree {
	ll ft[N + 5];
	void update(int pos, int val) {
		int idx = pos;
		while(idx <= N) {
			ft[idx] += val;
			idx += (idx & (-idx));
		}
	}
	ll get(int pos) {
		int idx = pos;
		ll ans = 0;
		while(idx > 0) {
			ans += ft[idx];
			idx -= (idx & (-idx));
		}
		return ans;
	}
} ft;
vi cdq(int l, int r) {
	vi f;
	vector<int> record;
	if(l == r) {
		f.pb(a[l]);
		return f;
	}
	int mid = (l + r)/2;
	vi a = cdq(l, mid);
	vi b = cdq(mid + 1, r);
	int i = 0, j = 0, cnt = 0;
	while(i < (int)a.size() && j < (int)b.size()) {
		if(a[i].b > b[j].b) {
			f.pb(a[i]);
			if(a[i].in) {
				cnt++;
				ft.update(pos[a[i].c], 1);
				record.pb(pos[a[i].c]);
			}
			i++;
		}
		else {
			if(!b[j].in) 
				ans[b[j].q] += cnt - ft.get(pos[b[j].c]);
			f.pb(b[j]);
			j++;
		}
	}
	while(i < (int)a.size()) {f.pb(a[i]); i++;}
	while(j < (int)b.size()) {
		if(!b[j].in)
			ans[b[j].q] += cnt - ft.get(pos[b[j].c]);
		f.pb(b[j]); 
		j++;
	}
	for(auto x: record) ft.update(x, -1);
	return f;
}
void solve() {
	cin>>n>>q;
	for(int i=1; i<=n + q; i++) {
		a[i].a = a[i].b = a[i].c = a[i].in = 0;
	}
	for(int i=1; i<=n; i++) {
		cin>>a[i].a>>a[i].b;
		a[i].c = a[i].a + a[i].b;
		a[i].in = 1;
	}
	for(int i=n + 1; i<=n + q; i++) {
		cin>>a[i].a>>a[i].b>>a[i].c;
		a[i].a--;
		a[i].b--;
		a[i].c--;
		a[i].q = i - n;
	}
	n += q;
	for(int i=1; i<=n; i++) {
		f.pb(a[i].a);
		f.pb(a[i].b);
		f.pb(a[i].c);
	}
	sort(f.begin(), f.end());
	f.erase(unique(f.begin(), f.end()), f.end());
	for(int i=0; i<(int)f.size(); i++) pos[f[i]] = i + 1;
	sort(a + 1, a + 1 + n, [](student x, student y){
		if(x.a != y.a) return x.a > y.a;
		if(x.b != y.b) return x.b < y.b;
		return x.c < y.c;
	}); 
	cdq(1, n);
	for(int i=1; i<=q; i++)
		cout<<ans[i]<<'\n';
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen(".INP", "r", stdin);
    // freopen(".OUT", "w", stdout);
    for(int tc=1; tc<=tt; tc++) solve();
    cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 14 ms 10288 KB Output is correct
8 Correct 14 ms 10340 KB Output is correct
9 Correct 14 ms 10320 KB Output is correct
10 Correct 11 ms 9996 KB Output is correct
11 Correct 10 ms 9996 KB Output is correct
12 Correct 5 ms 9464 KB Output is correct
13 Correct 11 ms 10252 KB Output is correct
14 Correct 11 ms 10252 KB Output is correct
15 Correct 11 ms 10248 KB Output is correct
16 Correct 6 ms 9676 KB Output is correct
17 Correct 10 ms 9816 KB Output is correct
18 Correct 4 ms 9464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 482 ms 54472 KB Output is correct
2 Correct 473 ms 52756 KB Output is correct
3 Correct 460 ms 52852 KB Output is correct
4 Correct 335 ms 51676 KB Output is correct
5 Correct 221 ms 50348 KB Output is correct
6 Correct 156 ms 47820 KB Output is correct
7 Correct 470 ms 55192 KB Output is correct
8 Correct 458 ms 52720 KB Output is correct
9 Correct 476 ms 54864 KB Output is correct
10 Correct 183 ms 44168 KB Output is correct
11 Correct 275 ms 45236 KB Output is correct
12 Correct 111 ms 40784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 482 ms 54472 KB Output is correct
2 Correct 473 ms 52756 KB Output is correct
3 Correct 460 ms 52852 KB Output is correct
4 Correct 335 ms 51676 KB Output is correct
5 Correct 221 ms 50348 KB Output is correct
6 Correct 156 ms 47820 KB Output is correct
7 Correct 470 ms 55192 KB Output is correct
8 Correct 458 ms 52720 KB Output is correct
9 Correct 476 ms 54864 KB Output is correct
10 Correct 183 ms 44168 KB Output is correct
11 Correct 275 ms 45236 KB Output is correct
12 Correct 111 ms 40784 KB Output is correct
13 Correct 673 ms 54292 KB Output is correct
14 Correct 631 ms 54136 KB Output is correct
15 Correct 440 ms 51548 KB Output is correct
16 Correct 447 ms 49476 KB Output is correct
17 Correct 328 ms 51688 KB Output is correct
18 Correct 157 ms 46880 KB Output is correct
19 Correct 675 ms 54036 KB Output is correct
20 Correct 622 ms 51704 KB Output is correct
21 Correct 644 ms 53896 KB Output is correct
22 Correct 169 ms 46260 KB Output is correct
23 Correct 284 ms 48632 KB Output is correct
24 Correct 111 ms 40912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 14 ms 10288 KB Output is correct
8 Correct 14 ms 10340 KB Output is correct
9 Correct 14 ms 10320 KB Output is correct
10 Correct 11 ms 9996 KB Output is correct
11 Correct 10 ms 9996 KB Output is correct
12 Correct 5 ms 9464 KB Output is correct
13 Correct 11 ms 10252 KB Output is correct
14 Correct 11 ms 10252 KB Output is correct
15 Correct 11 ms 10248 KB Output is correct
16 Correct 6 ms 9676 KB Output is correct
17 Correct 10 ms 9816 KB Output is correct
18 Correct 4 ms 9464 KB Output is correct
19 Correct 482 ms 54472 KB Output is correct
20 Correct 473 ms 52756 KB Output is correct
21 Correct 460 ms 52852 KB Output is correct
22 Correct 335 ms 51676 KB Output is correct
23 Correct 221 ms 50348 KB Output is correct
24 Correct 156 ms 47820 KB Output is correct
25 Correct 470 ms 55192 KB Output is correct
26 Correct 458 ms 52720 KB Output is correct
27 Correct 476 ms 54864 KB Output is correct
28 Correct 183 ms 44168 KB Output is correct
29 Correct 275 ms 45236 KB Output is correct
30 Correct 111 ms 40784 KB Output is correct
31 Correct 673 ms 54292 KB Output is correct
32 Correct 631 ms 54136 KB Output is correct
33 Correct 440 ms 51548 KB Output is correct
34 Correct 447 ms 49476 KB Output is correct
35 Correct 328 ms 51688 KB Output is correct
36 Correct 157 ms 46880 KB Output is correct
37 Correct 675 ms 54036 KB Output is correct
38 Correct 622 ms 51704 KB Output is correct
39 Correct 644 ms 53896 KB Output is correct
40 Correct 169 ms 46260 KB Output is correct
41 Correct 284 ms 48632 KB Output is correct
42 Correct 111 ms 40912 KB Output is correct
43 Correct 884 ms 77004 KB Output is correct
44 Correct 889 ms 78380 KB Output is correct
45 Correct 957 ms 78776 KB Output is correct
46 Correct 683 ms 63476 KB Output is correct
47 Correct 557 ms 67152 KB Output is correct
48 Correct 150 ms 47088 KB Output is correct
49 Correct 944 ms 79844 KB Output is correct
50 Correct 895 ms 78276 KB Output is correct
51 Correct 1031 ms 75208 KB Output is correct
52 Correct 461 ms 54244 KB Output is correct
53 Correct 361 ms 52052 KB Output is correct