답안 #1046882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046882 2024-08-07T05:41:11 Z vjudge1 Index (COCI21_index) C++17
110 / 110
284 ms 6232 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 = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 2e5 + 5;
 
const ll SQ = 500;
vector<pair<pair<int,int>,int>> query;
vector<int> A;
int ans[MAXN], suff[MAXN], res = 1, cnt = 1;
void insert(int x) {
	suff[A[x]]++;
	if (A[x] >= res)
		cnt++;
 
	if (cnt - suff[res] > res) {
		cnt -= suff[res];
		res++;
	}
}
 
void omit(int x) {
	suff[A[x]]--;
	if (A[x] >= res)
		cnt--;
 
	if (cnt < res) {
		res--;
		cnt += suff[res];
	}
}
 
int main() {
	fast
	int N, Q;
	cin >> N >> Q;
 
	A = vector<int>(N+1);
	query = vector<pair<pair<int,int>,int>>(Q);
	for (int i = 1; i <= N; i++)
		cin >> A[i];
	for (int i = 0; i < Q; i++) {
		cin >> query[i].f.f >> query[i].f.s;
		query[i].s = i;
	}
	sort(query.begin(), query.end(), [&](pair<pair<int,int>,int> a, pair<pair<int,int>,int> b) {
		return make_pair(a.f.f / SQ, a.f.s) < make_pair(b.f.f / SQ, b.f.s);
	});
 
	int l = 1, r = 1;
	suff[A[1]]++;
	for (auto u : query) {
		int new_l = u.f.f;
		int new_r = u.f.s;
		while (new_l < l) {
			l--;
			insert(l);
		}
		
		while (new_r > r) {
			r++;
			insert(r);
		}
		
		while (new_l > l) {
			omit(l);
			l++;
		}
		
		while (new_r < r) {
			omit(r);
			r--;
		}
 
		ans[u.s] = res;
	}
 
	for (int i = 0; i < Q; i++)
		cout << ans[i] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 496 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 496 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 56 ms 1872 KB Output is correct
12 Correct 55 ms 1872 KB Output is correct
13 Correct 70 ms 1872 KB Output is correct
14 Correct 56 ms 1884 KB Output is correct
15 Correct 61 ms 1872 KB Output is correct
16 Correct 70 ms 1888 KB Output is correct
17 Correct 56 ms 1872 KB Output is correct
18 Correct 57 ms 1876 KB Output is correct
19 Correct 72 ms 1876 KB Output is correct
20 Correct 64 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 496 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 56 ms 1872 KB Output is correct
12 Correct 55 ms 1872 KB Output is correct
13 Correct 70 ms 1872 KB Output is correct
14 Correct 56 ms 1884 KB Output is correct
15 Correct 61 ms 1872 KB Output is correct
16 Correct 70 ms 1888 KB Output is correct
17 Correct 56 ms 1872 KB Output is correct
18 Correct 57 ms 1876 KB Output is correct
19 Correct 72 ms 1876 KB Output is correct
20 Correct 64 ms 1876 KB Output is correct
21 Correct 264 ms 6224 KB Output is correct
22 Correct 248 ms 6228 KB Output is correct
23 Correct 250 ms 6224 KB Output is correct
24 Correct 245 ms 6160 KB Output is correct
25 Correct 261 ms 6232 KB Output is correct
26 Correct 244 ms 6168 KB Output is correct
27 Correct 272 ms 6228 KB Output is correct
28 Correct 247 ms 6144 KB Output is correct
29 Correct 268 ms 6228 KB Output is correct
30 Correct 284 ms 6172 KB Output is correct