Submission #555537

# Submission time Handle Problem Language Result Execution time Memory
555537 2022-05-01T07:23:02 Z fuad27 Nekameleoni (COCI15_nekameleoni) C++17
14 / 140
3000 ms 4300 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 () {
      ios_base::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
    	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 1166 ms 1332 KB Output is correct
2 Correct 122 ms 1344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3075 ms 1364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 1364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3071 ms 1476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 3412 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 3156 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 3464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 3664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 4144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 4300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -