답안 #123688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123688 2019-07-02T04:09:22 Z 김현수(#3336) Examination (JOI19_examination) C++14
100 / 100
974 ms 57860 KB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;

const int L = 131072;

int n, q, ans[L];
pair<int,int> a[L];

vector<int> cpr;
vector<pair<int, pair<int,int> > > v;
vector<pair<pair<int,int>, pair<int,int> > > w;

struct seg1D {
	vector<int> v, i;
	void init (int X) {
		i.push_back(X);
		v.assign(2, 0);
	}
	void init (seg1D &A, seg1D &B) {
		for(auto &T : A.i) i.push_back(T);
		for(auto &T : B.i) i.push_back(T);
		sort(i.begin(), i.end());
		v.assign(i.size() * 2, 0);
	}
	void upd (int I, int V) {
		int P = lower_bound(i.begin(), i.end(), I) - i.begin();
		P += i.size();
		while(P) {
			v[P] += V;
			P /= 2;
		}
	}
	int get (int I) {
		int S = lower_bound(i.begin(), i.end(), I) - i.begin();
		int E = (int)i.size() - 1;
		S += i.size(); E += i.size();
		int R = 0;
		while(S <= E) {
			if(S%2 == 1) R += v[S++];
			if(E%2 == 0) R += v[E--];
			S /= 2; E /= 2;
		}
		return R;
	}
};

struct seg2D {
	seg1D v[2*L];
	void init () {
		for(int i=0;i<L;i++) {
			v[L+i].init(i < n ? a[i].Y : 0);
		}
		for(int i=L;--i;) {
			v[i].init(v[2*i], v[2*i+1]);
		}
	}
	void upd (int A, int B, int V) {
		A += L;
		while(A) {
			v[A].upd(B, V);
			A /= 2;
		}
	}
	int get (int A, int B) {
		int S = A + L, E = L-1 + L;
		int R = 0;
		while(S <= E) {
			if(S%2 == 1) R += v[S++].get(B);
			if(E%2 == 0) R += v[E--].get(B);
			S /= 2; E /= 2;
		}
		return R;
	}
} seg;

int main()
{
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++) {
		scanf("%d%d",&a[i].X,&a[i].Y);
	}
	sort(a, a+n);
	for(int i=0;i<n;i++) {
		v.push_back({a[i].X + a[i].Y, {i, a[i].Y}});
		cpr.push_back(a[i].X);
	}
	seg.init();
	for(int i=1;i<=q;i++) {
		int A, B, C;
		scanf("%d%d%d",&A,&B,&C);
		A = lower_bound(cpr.begin(), cpr.end(), A) - cpr.begin();
		w.push_back({{C, i}, {A, B}});
	}
	sort(v.begin(), v.end());
	sort(w.begin(), w.end());
	for(int i=w.size(),j=(int)v.size()-1;i--;) {
		while(j >= 0 && v[j].X >= w[i].X.X) {
			seg.upd(v[j].Y.X, v[j].Y.Y, 1);
			j--;
		}
		ans[w[i].X.Y] = seg.get(w[i].Y.X, w[i].Y.Y);
	}
	for(int i=1;i<=q;i++) {
		printf("%d\n", ans[i]);
	}
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:80:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~
examination.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a[i].X,&a[i].Y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&A,&B,&C);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 51952 KB Output is correct
2 Correct 113 ms 52080 KB Output is correct
3 Correct 114 ms 52036 KB Output is correct
4 Correct 112 ms 51924 KB Output is correct
5 Correct 112 ms 51952 KB Output is correct
6 Correct 112 ms 51952 KB Output is correct
7 Correct 125 ms 52208 KB Output is correct
8 Correct 125 ms 52080 KB Output is correct
9 Correct 124 ms 52080 KB Output is correct
10 Correct 123 ms 52208 KB Output is correct
11 Correct 122 ms 52080 KB Output is correct
12 Correct 119 ms 52052 KB Output is correct
13 Correct 135 ms 52080 KB Output is correct
14 Correct 123 ms 52032 KB Output is correct
15 Correct 123 ms 52080 KB Output is correct
16 Correct 119 ms 52088 KB Output is correct
17 Correct 119 ms 52080 KB Output is correct
18 Correct 117 ms 52068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 798 ms 57584 KB Output is correct
2 Correct 826 ms 57540 KB Output is correct
3 Correct 814 ms 57624 KB Output is correct
4 Correct 488 ms 57636 KB Output is correct
5 Correct 481 ms 57860 KB Output is correct
6 Correct 298 ms 57508 KB Output is correct
7 Correct 782 ms 57632 KB Output is correct
8 Correct 738 ms 57764 KB Output is correct
9 Correct 717 ms 57596 KB Output is correct
10 Correct 361 ms 57408 KB Output is correct
11 Correct 354 ms 57388 KB Output is correct
12 Correct 261 ms 57252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 798 ms 57584 KB Output is correct
2 Correct 826 ms 57540 KB Output is correct
3 Correct 814 ms 57624 KB Output is correct
4 Correct 488 ms 57636 KB Output is correct
5 Correct 481 ms 57860 KB Output is correct
6 Correct 298 ms 57508 KB Output is correct
7 Correct 782 ms 57632 KB Output is correct
8 Correct 738 ms 57764 KB Output is correct
9 Correct 717 ms 57596 KB Output is correct
10 Correct 361 ms 57408 KB Output is correct
11 Correct 354 ms 57388 KB Output is correct
12 Correct 261 ms 57252 KB Output is correct
13 Correct 846 ms 57552 KB Output is correct
14 Correct 853 ms 57636 KB Output is correct
15 Correct 806 ms 57692 KB Output is correct
16 Correct 534 ms 57776 KB Output is correct
17 Correct 555 ms 57768 KB Output is correct
18 Correct 332 ms 57484 KB Output is correct
19 Correct 974 ms 57556 KB Output is correct
20 Correct 842 ms 57724 KB Output is correct
21 Correct 848 ms 57608 KB Output is correct
22 Correct 394 ms 57512 KB Output is correct
23 Correct 366 ms 57352 KB Output is correct
24 Correct 256 ms 57256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 51952 KB Output is correct
2 Correct 113 ms 52080 KB Output is correct
3 Correct 114 ms 52036 KB Output is correct
4 Correct 112 ms 51924 KB Output is correct
5 Correct 112 ms 51952 KB Output is correct
6 Correct 112 ms 51952 KB Output is correct
7 Correct 125 ms 52208 KB Output is correct
8 Correct 125 ms 52080 KB Output is correct
9 Correct 124 ms 52080 KB Output is correct
10 Correct 123 ms 52208 KB Output is correct
11 Correct 122 ms 52080 KB Output is correct
12 Correct 119 ms 52052 KB Output is correct
13 Correct 135 ms 52080 KB Output is correct
14 Correct 123 ms 52032 KB Output is correct
15 Correct 123 ms 52080 KB Output is correct
16 Correct 119 ms 52088 KB Output is correct
17 Correct 119 ms 52080 KB Output is correct
18 Correct 117 ms 52068 KB Output is correct
19 Correct 798 ms 57584 KB Output is correct
20 Correct 826 ms 57540 KB Output is correct
21 Correct 814 ms 57624 KB Output is correct
22 Correct 488 ms 57636 KB Output is correct
23 Correct 481 ms 57860 KB Output is correct
24 Correct 298 ms 57508 KB Output is correct
25 Correct 782 ms 57632 KB Output is correct
26 Correct 738 ms 57764 KB Output is correct
27 Correct 717 ms 57596 KB Output is correct
28 Correct 361 ms 57408 KB Output is correct
29 Correct 354 ms 57388 KB Output is correct
30 Correct 261 ms 57252 KB Output is correct
31 Correct 846 ms 57552 KB Output is correct
32 Correct 853 ms 57636 KB Output is correct
33 Correct 806 ms 57692 KB Output is correct
34 Correct 534 ms 57776 KB Output is correct
35 Correct 555 ms 57768 KB Output is correct
36 Correct 332 ms 57484 KB Output is correct
37 Correct 974 ms 57556 KB Output is correct
38 Correct 842 ms 57724 KB Output is correct
39 Correct 848 ms 57608 KB Output is correct
40 Correct 394 ms 57512 KB Output is correct
41 Correct 366 ms 57352 KB Output is correct
42 Correct 256 ms 57256 KB Output is correct
43 Correct 857 ms 57664 KB Output is correct
44 Correct 853 ms 57608 KB Output is correct
45 Correct 863 ms 57636 KB Output is correct
46 Correct 547 ms 57584 KB Output is correct
47 Correct 537 ms 57636 KB Output is correct
48 Correct 323 ms 57376 KB Output is correct
49 Correct 888 ms 57552 KB Output is correct
50 Correct 882 ms 57508 KB Output is correct
51 Correct 774 ms 57740 KB Output is correct
52 Correct 446 ms 57384 KB Output is correct
53 Correct 358 ms 57376 KB Output is correct