답안 #854013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854013 2023-09-25T19:46:38 Z serifefedartar Examination (JOI19_examination) C++17
100 / 100
950 ms 12792 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 1e5 + 5;

const int BLOCK = 500;
struct Query {
	int A, B, C, idx;
	bool operator< (Query y) {	
		return make_pair(A / BLOCK, B) < make_pair(y.A / BLOCK, y.B);
	}
};

vector<Query> Q;
int fen[MAXN], ans[MAXN], sumCoor[MAXN];
vector<int> S, T, cc;
vector<pair<int,int>> tt, ss;
int cnt[MAXN];

void update(int k, int val) {
	k++;
	while (k < MAXN) {
		fen[k] += val;
		k += k & -k;
	}
}

int get(int k) {
	k++;
	int res = 0;
	while (k >= 1) {
		res += fen[k];
		k -= k & -k;
	}
	return res;
}

int main() {
	fast
	int N, Qs;
	cin >> N >> Qs;

	S = vector<int>(N);
	T = vector<int>(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i] >> T[i];
		ss.push_back({S[i], i});
		tt.push_back({T[i], i});
		cc.push_back(S[i] + T[i]);
	}

	sort(cc.begin(), cc.end());
	sort(ss.begin(), ss.end());
	sort(tt.begin(), tt.end());

	for (int i = 0; i < N; i++)
		sumCoor[i] = lower_bound(cc.begin(), cc.end(), S[i] + T[i]) - cc.begin();

	for (int i = 0; i < Qs; i++) {
		Query q;
		cin >> q.A >> q.B >> q.C;
		q.A = lower_bound(ss.begin(), ss.end(), make_pair(q.A, 0)) - ss.begin();
		q.B = lower_bound(tt.begin(), tt.end(), make_pair(q.B, 0)) - tt.begin();
		q.C = lower_bound(cc.begin(), cc.end(), q.C) - cc.begin();
		q.idx = i;
		Q.push_back(q);
	}
	sort(Q.begin(), Q.end());

	int s = N; // tamamen sağda
	int t = N;
	for (auto u : Q) {
		int new_s = u.A;
		int new_t = u.B;
		while (new_s < s) {
			cnt[ss[s-1].s]++;
			if (cnt[ss[s-1].s] == 2)
				update(sumCoor[ss[s-1].s], 1);				
			s--;
		}
		while (new_t < t) {
			cnt[tt[t-1].s]++;
			if (cnt[tt[t-1].s] == 2)
				update(sumCoor[tt[t-1].s], 1);
			t--;
		}
		while (new_s > s) {
			cnt[ss[s].s]--;
			if (cnt[ss[s].s] == 1)
				update(sumCoor[ss[s].s], -1);
			s++;
		}
		while (new_t > t) {
			cnt[tt[t].s]--;
			if (cnt[tt[t].s] == 1)
				update(sumCoor[tt[t].s], -1);
			t++;
		}

		ans[u.idx] = get(MAXN - 2) - get(u.C - 1);
	}

	for (int i = 0; i < Qs; i++)
		cout << ans[i] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 8 ms 604 KB Output is correct
8 Correct 8 ms 600 KB Output is correct
9 Correct 9 ms 600 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
11 Correct 6 ms 600 KB Output is correct
12 Correct 6 ms 856 KB Output is correct
13 Correct 8 ms 600 KB Output is correct
14 Correct 8 ms 600 KB Output is correct
15 Correct 8 ms 600 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 7884 KB Output is correct
2 Correct 918 ms 10520 KB Output is correct
3 Correct 917 ms 10484 KB Output is correct
4 Correct 710 ms 9720 KB Output is correct
5 Correct 131 ms 9464 KB Output is correct
6 Correct 97 ms 8696 KB Output is correct
7 Correct 323 ms 10276 KB Output is correct
8 Correct 369 ms 10232 KB Output is correct
9 Correct 322 ms 10244 KB Output is correct
10 Correct 93 ms 9872 KB Output is correct
11 Correct 702 ms 9396 KB Output is correct
12 Correct 49 ms 8180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 7884 KB Output is correct
2 Correct 918 ms 10520 KB Output is correct
3 Correct 917 ms 10484 KB Output is correct
4 Correct 710 ms 9720 KB Output is correct
5 Correct 131 ms 9464 KB Output is correct
6 Correct 97 ms 8696 KB Output is correct
7 Correct 323 ms 10276 KB Output is correct
8 Correct 369 ms 10232 KB Output is correct
9 Correct 322 ms 10244 KB Output is correct
10 Correct 93 ms 9872 KB Output is correct
11 Correct 702 ms 9396 KB Output is correct
12 Correct 49 ms 8180 KB Output is correct
13 Correct 936 ms 10804 KB Output is correct
14 Correct 925 ms 10744 KB Output is correct
15 Correct 919 ms 10368 KB Output is correct
16 Correct 718 ms 10012 KB Output is correct
17 Correct 145 ms 9976 KB Output is correct
18 Correct 100 ms 8692 KB Output is correct
19 Correct 950 ms 10664 KB Output is correct
20 Correct 949 ms 10788 KB Output is correct
21 Correct 525 ms 11016 KB Output is correct
22 Correct 91 ms 9468 KB Output is correct
23 Correct 713 ms 9464 KB Output is correct
24 Correct 55 ms 8188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 8 ms 604 KB Output is correct
8 Correct 8 ms 600 KB Output is correct
9 Correct 9 ms 600 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
11 Correct 6 ms 600 KB Output is correct
12 Correct 6 ms 856 KB Output is correct
13 Correct 8 ms 600 KB Output is correct
14 Correct 8 ms 600 KB Output is correct
15 Correct 8 ms 600 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 921 ms 7884 KB Output is correct
20 Correct 918 ms 10520 KB Output is correct
21 Correct 917 ms 10484 KB Output is correct
22 Correct 710 ms 9720 KB Output is correct
23 Correct 131 ms 9464 KB Output is correct
24 Correct 97 ms 8696 KB Output is correct
25 Correct 323 ms 10276 KB Output is correct
26 Correct 369 ms 10232 KB Output is correct
27 Correct 322 ms 10244 KB Output is correct
28 Correct 93 ms 9872 KB Output is correct
29 Correct 702 ms 9396 KB Output is correct
30 Correct 49 ms 8180 KB Output is correct
31 Correct 936 ms 10804 KB Output is correct
32 Correct 925 ms 10744 KB Output is correct
33 Correct 919 ms 10368 KB Output is correct
34 Correct 718 ms 10012 KB Output is correct
35 Correct 145 ms 9976 KB Output is correct
36 Correct 100 ms 8692 KB Output is correct
37 Correct 950 ms 10664 KB Output is correct
38 Correct 949 ms 10788 KB Output is correct
39 Correct 525 ms 11016 KB Output is correct
40 Correct 91 ms 9468 KB Output is correct
41 Correct 713 ms 9464 KB Output is correct
42 Correct 55 ms 8188 KB Output is correct
43 Correct 938 ms 12764 KB Output is correct
44 Correct 940 ms 12792 KB Output is correct
45 Correct 936 ms 12792 KB Output is correct
46 Correct 722 ms 11184 KB Output is correct
47 Correct 149 ms 11228 KB Output is correct
48 Correct 100 ms 8540 KB Output is correct
49 Correct 344 ms 12532 KB Output is correct
50 Correct 389 ms 12536 KB Output is correct
51 Correct 340 ms 12508 KB Output is correct
52 Correct 109 ms 11000 KB Output is correct
53 Correct 697 ms 10348 KB Output is correct