Submission #555531

# Submission time Handle Problem Language Result Execution time Memory
555531 2022-05-01T07:19:47 Z fuad27 Nekameleoni (COCI15_nekameleoni) C++17
14 / 140
3000 ms 4208 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
const int MAXK = 50;
vector<int> fen[50];
void update(int in, int val, int bt) {
	in++;
	while(in < MAXN) {
		fen[bt][in]+=val;
		in+=in&(-in);
	}
}
long long query(int l, int bt) {
	l++;
	long long sum = 0;
	while(l > 0) {
		sum+=fen[bt][l];
		l-=l&(-l);
	}
	return sum;
}
long long k;
bool check(int l, int r) {
	bool c = true;
	for(int i = 0;i<k;i++) {
		if(!(query(r, i) - query(l-1, i)))c = false;
	}	
	return c;
}
int main () {
	long long n, m;
	cin >> n >> k >> m;
	for(int i = 0;i<50;i++) {
		fen[i].resize(MAXN);
	}
	long long arr[n];
	for(int i = 0;i<n;i++){
		cin >> arr[i];
		arr[i]--;
	}
	for(int i = 0;i<n;i++) {
		update(i, 1, arr[i]);
	}
	while(m--) {
		int type;
		cin >> type;
		if(type == 1) {
			int p, v;
			cin >> p >> v;
			v--;p--;
			update(p, -1, arr[p]);
			arr[p] = v;
			update(p, 1, arr[p]);
		}
		else {
			int p1 = 0, p2 = 0;
			long long ans = 1e9;
			while(p2 < n) {
				if(check(p1, p2)) {
					ans = min(ans, (long long)p2-p1+1);
					p1++;
				}
				else {
					p2++;
				}
			}
			if(ans == 1e9)ans = -1;
			cout << ans << "\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1138 ms 1236 KB Output is correct
2 Correct 120 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3071 ms 1344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3086 ms 1364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 2900 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 3272 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 3012 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 3636 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 45 ms 3404 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 4208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 4160 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -