CSES - Putka Open 2015 – finaali - Results
Submission details
Task:Kyselyt
Sender:
Submission time:2015-12-20 17:10:44 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:81:4: error: 'set' was not declared in this scope
    set<int> s;
    ^
input/code.cpp:81:8: error: expected primary-expression before 'int'
    set<int> s;
        ^
input/code.cpp:83:5: error: 's' was not declared in this scope
     s.insert(e[x]);
     ^

Code

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define ll long long
#define N (2<<16)

using namespace std;

long v[2*N];
long m[2*N];

void c (int k, long a) {
	k += N;
	v[k] = a;
	//cout<<"foo: "<<k<<endl;
	m[k] = a;
	for (k /= 2; k > 0; k /= 2) {
		v[k] = v[2*k] + v[2*k+1];
		m[k] = min(m[2*k], v[2*k+1]);
	}
}

void qu (long a, long b) {
	a += N;
	b += N;
	long w = (b - a + 1);
	long s = 0;
	long mn = 100000;
	while (a <= b) {
		if (a % 2 == 1) {
			mn = min(mn, m[a]);
			s += v[a++];
		}
		if (b % 2 == 0) {
			mn = min(mn, m[b]);
			s += v[b--];
		}
		a /= 2;
		b /= 2;
	}

	s -= (mn - 1) * w;
	//cout<<s<<" "<<(w * (w + 1) / 2)<<endl;
	if (s == (w * (w + 1) / 2)) cout<<"10-4"<<endl;
	else cout<<"QAQ"<<endl;
}

int main () {
	int n, q;
	cin>>n>>q;
	if (n > 1000 || q > 1000) {
		for (int i = 0; i < n; i++) {
			int k;
			cin>>k;
			c(i + 1, k);
		}
		for (int i = 0; i < q; i++) {
			char x;
			cin>>x;
			int a, b;
			cin>>a>>b;
			//a--; b--;
			if (x == '!') {
				long l = v[a + N];
				//cout<<l<<" "<<(a + N)<<":"<<v[b + N]<<" "<<(b + N)<<endl;
				c(a, v[b + N]);
				c(b, l);
			} else {
				qu(a, b);
			}
		}
	} else {
		int e[n];
		for (int i = 0; i < n; i++) cin>>e[i];
		for (int i = 0; i < q; i++) {
			char c;			
			cin>>c;
			int a, b;
			cin>>a>>b;
			set<int> s;
			for (int x = a - 1; x < b; x++) {
				s.insert(e[x]);
				if (*s.end() - *s.begin() == b - a) cout<<"10-4"<<endl;
				else cout<<"QAQ"<<endl;
			}
		}
	}
}