Submission #369621

# Submission time Handle Problem Language Result Execution time Memory
369621 2021-02-22T05:55:58 Z mario05092929 Examination (JOI19_examination) C++11
100 / 100
471 ms 27484 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(),v.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast") 
#pragma gcc optimize("unroll-loops")
using namespace std;
const int INF = 1e9;
const int TMX = 1 << 18;
const long long llINF = 2e18;
const long long mod = 1e9+7;
const long long hashmod = 100003;
const int MAXN = 100000;
const int MAXM = 1000000;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef pair <ll,ll> pl;
typedef vector <int> vec;
typedef vector <pi> vecpi;
typedef long long ll;
int n,Q,m;
vec rev;
int ans[100005];
int t[600005];

void update(int x,int val) {
	for(;x <= m;x += x&-x) t[x] += val;
}

int query(int l,int r) {
	if(l > r) return 0;
	int ret = 0;
	for(;r;r -= r&-r) ret += t[r];
	for(l--;l;l -= l&-l) ret -= t[l];
	return ret;
}

struct Score {
	int x,y,z,idx;
}a[100005],q[100005];

bool cmp(Score x,Score y) {
	if(x.x == y.x) {
		if(x.y == y.y) return x.z < y.z;
		return x.y < y.y;
	}
	return x.x < y.x;
}

void DnC(int nl,int nr,int ql,int qr) {
	if(ql > qr) return;
	if(ql == qr||nl == nr) {
		for(int i = nl;i <= nr;i++) {
			for(int j = ql;j <= qr;j++) {
				ans[q[j].idx] += (a[i].x >= q[j].x&&a[i].y >= q[j].y&&a[i].z >= q[j].z);
			}
		}
		return;
	}
	int midn = (nl + nr) >> 1;
	int midq = ql,g = 0;
	while(midq <= qr&&q[midq].x <= a[midn].x) midq++;
	vector <Score> L,R;
	for(int i = midn+1;i <= nr;i++) R.pb({-a[i].y,a[i].z,i});
	for(int i = ql;i < midq;i++) L.pb({-q[i].y,q[i].z,i});
	sort(all(L),cmp), sort(all(R),cmp);
	for(Score i : L) {
		while(g < R.size()&&R[g].x <= i.x) update(R[g++].y,1);
		ans[q[i.z].idx] += query(i.y,m);
	}
	for(int i = 0;i < g;i++) update(R[i].y,-1);
	DnC(nl,midn,ql,midq-1);
	DnC(midn+1,nr,midq,qr);
}

int getIdx(int x) {return lower_bound(all(rev),x)-rev.begin()+1;}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> Q;
	for(int i = 1;i <= n;i++) {
		cin >> a[i].x >> a[i].y;
		a[i].z = a[i].x+a[i].y;
		rev.pb(a[i].x), rev.pb(a[i].y), rev.pb(a[i].z);
	}
	for(int i = 1;i <= Q;i++) {
		cin >> q[i].x >> q[i].y >> q[i].z;
		q[i].idx = i;
		rev.pb(q[i].x), rev.pb(q[i].y), rev.pb(q[i].z);
	}
	sort(all(rev)); rev.erase(unique(all(rev)),rev.end());
	m = rev.size();
	for(int i = 1;i <= n;i++) {
		a[i].x = getIdx(a[i].x);
		a[i].y = getIdx(a[i].y);
		a[i].z = getIdx(a[i].z);
	}
	for(int i = 1;i <= Q;i++) {
		q[i].x = getIdx(q[i].x);
		q[i].y = getIdx(q[i].y);
		q[i].z = getIdx(q[i].z);
	}
	sort(a+1,a+n+1,cmp), sort(q+1,q+Q+1,cmp);
	DnC(1,n,1,Q);
	for(int i = 1;i <= Q;i++) cout << ans[i] << '\n';
}

Compilation message

examination.cpp:6: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
    6 | #pragma gcc optimize("O3")
      | 
examination.cpp:7: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
    7 | #pragma gcc optimize("Ofast")
      | 
examination.cpp:8: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
    8 | #pragma gcc optimize("unroll-loops")
      | 
examination.cpp: In function 'void DnC(int, int, int, int)':
examination.cpp:71:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Score>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   while(g < R.size()&&R[g].x <= i.x) update(R[g++].y,1);
      |         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 10 ms 876 KB Output is correct
8 Correct 10 ms 876 KB Output is correct
9 Correct 10 ms 876 KB Output is correct
10 Correct 9 ms 876 KB Output is correct
11 Correct 8 ms 876 KB Output is correct
12 Correct 6 ms 876 KB Output is correct
13 Correct 9 ms 876 KB Output is correct
14 Correct 9 ms 864 KB Output is correct
15 Correct 9 ms 876 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 8 ms 876 KB Output is correct
18 Correct 4 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 13488 KB Output is correct
2 Correct 380 ms 13532 KB Output is correct
3 Correct 383 ms 13404 KB Output is correct
4 Correct 370 ms 12636 KB Output is correct
5 Correct 279 ms 15836 KB Output is correct
6 Correct 257 ms 14684 KB Output is correct
7 Correct 363 ms 17908 KB Output is correct
8 Correct 383 ms 13404 KB Output is correct
9 Correct 358 ms 18396 KB Output is correct
10 Correct 248 ms 25180 KB Output is correct
11 Correct 313 ms 12380 KB Output is correct
12 Correct 174 ms 16604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 13488 KB Output is correct
2 Correct 380 ms 13532 KB Output is correct
3 Correct 383 ms 13404 KB Output is correct
4 Correct 370 ms 12636 KB Output is correct
5 Correct 279 ms 15836 KB Output is correct
6 Correct 257 ms 14684 KB Output is correct
7 Correct 363 ms 17908 KB Output is correct
8 Correct 383 ms 13404 KB Output is correct
9 Correct 358 ms 18396 KB Output is correct
10 Correct 248 ms 25180 KB Output is correct
11 Correct 313 ms 12380 KB Output is correct
12 Correct 174 ms 16604 KB Output is correct
13 Correct 426 ms 14100 KB Output is correct
14 Correct 418 ms 14044 KB Output is correct
15 Correct 385 ms 13524 KB Output is correct
16 Correct 401 ms 13020 KB Output is correct
17 Correct 313 ms 16220 KB Output is correct
18 Correct 304 ms 14720 KB Output is correct
19 Correct 421 ms 14084 KB Output is correct
20 Correct 422 ms 13940 KB Output is correct
21 Correct 396 ms 15580 KB Output is correct
22 Correct 246 ms 25052 KB Output is correct
23 Correct 310 ms 12380 KB Output is correct
24 Correct 175 ms 16504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 10 ms 876 KB Output is correct
8 Correct 10 ms 876 KB Output is correct
9 Correct 10 ms 876 KB Output is correct
10 Correct 9 ms 876 KB Output is correct
11 Correct 8 ms 876 KB Output is correct
12 Correct 6 ms 876 KB Output is correct
13 Correct 9 ms 876 KB Output is correct
14 Correct 9 ms 864 KB Output is correct
15 Correct 9 ms 876 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 8 ms 876 KB Output is correct
18 Correct 4 ms 876 KB Output is correct
19 Correct 385 ms 13488 KB Output is correct
20 Correct 380 ms 13532 KB Output is correct
21 Correct 383 ms 13404 KB Output is correct
22 Correct 370 ms 12636 KB Output is correct
23 Correct 279 ms 15836 KB Output is correct
24 Correct 257 ms 14684 KB Output is correct
25 Correct 363 ms 17908 KB Output is correct
26 Correct 383 ms 13404 KB Output is correct
27 Correct 358 ms 18396 KB Output is correct
28 Correct 248 ms 25180 KB Output is correct
29 Correct 313 ms 12380 KB Output is correct
30 Correct 174 ms 16604 KB Output is correct
31 Correct 426 ms 14100 KB Output is correct
32 Correct 418 ms 14044 KB Output is correct
33 Correct 385 ms 13524 KB Output is correct
34 Correct 401 ms 13020 KB Output is correct
35 Correct 313 ms 16220 KB Output is correct
36 Correct 304 ms 14720 KB Output is correct
37 Correct 421 ms 14084 KB Output is correct
38 Correct 422 ms 13940 KB Output is correct
39 Correct 396 ms 15580 KB Output is correct
40 Correct 246 ms 25052 KB Output is correct
41 Correct 310 ms 12380 KB Output is correct
42 Correct 175 ms 16504 KB Output is correct
43 Correct 471 ms 17704 KB Output is correct
44 Correct 471 ms 17500 KB Output is correct
45 Correct 468 ms 17668 KB Output is correct
46 Correct 431 ms 15324 KB Output is correct
47 Correct 344 ms 18268 KB Output is correct
48 Correct 288 ms 14812 KB Output is correct
49 Correct 449 ms 22752 KB Output is correct
50 Correct 465 ms 17500 KB Output is correct
51 Correct 446 ms 22620 KB Output is correct
52 Correct 305 ms 27484 KB Output is correct
53 Correct 326 ms 13420 KB Output is correct