답안 #854011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854011 2023-09-25T19:44:43 Z serifefedartar Examination (JOI19_examination) C++17
2 / 100
3000 ms 11564 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 = 2e5 + 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;
map<int,int> cnt;

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 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 57 ms 2804 KB Output is correct
8 Correct 61 ms 2900 KB Output is correct
9 Correct 57 ms 3044 KB Output is correct
10 Correct 58 ms 2648 KB Output is correct
11 Correct 39 ms 2652 KB Output is correct
12 Correct 37 ms 2796 KB Output is correct
13 Correct 57 ms 2800 KB Output is correct
14 Correct 63 ms 2904 KB Output is correct
15 Correct 57 ms 2812 KB Output is correct
16 Correct 5 ms 2652 KB Output is correct
17 Correct 53 ms 2796 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3087 ms 11564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3087 ms 11564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 57 ms 2804 KB Output is correct
8 Correct 61 ms 2900 KB Output is correct
9 Correct 57 ms 3044 KB Output is correct
10 Correct 58 ms 2648 KB Output is correct
11 Correct 39 ms 2652 KB Output is correct
12 Correct 37 ms 2796 KB Output is correct
13 Correct 57 ms 2800 KB Output is correct
14 Correct 63 ms 2904 KB Output is correct
15 Correct 57 ms 2812 KB Output is correct
16 Correct 5 ms 2652 KB Output is correct
17 Correct 53 ms 2796 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Execution timed out 3087 ms 11564 KB Time limit exceeded
20 Halted 0 ms 0 KB -