CSES - APIO 2012 - Results
Submission details
Task:Guard
Sender:ArktinenKarpalo
Submission time:2019-03-17 15:57:33 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:51:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(!noni[j])
     ^~
input/code.cpp:53:6: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
      nii--; //
      ^~~
input/code.cpp:45:9: warning: variable 'okk' set but not used [-Wunused-but-set-variable]
    bool okk = false;
         ^~~
input/code.cpp:59:8: error: 'okk' was not declared in this scope
    if(!okk) {
        ^~~
input/code.cpp:59:8: note: suggested alternative: 'ok'
    if(!okk) {
        ^~~
        ok
input/code.cpp:66:6: error: 'bk' was not declared in this scope
   if(bk)
      ^~
input/code.cpp:66:6: note: suggested alternative: 'ok'
   if(bk)
      ^~
      ok
input/code.cpp:67:4: error: continue statement not within a loop
    continue;
    ^~~~~~~~
input/code.cpp:69:7: error: 'nii' was not declared in this scope
    if(nii == 0)
       ^~~
input/code.cpp:69:7: note: sugges...

Code

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define N (1<<18)
#define M 100000007
#define P complex<long long>
#define X real()
#define Y imag()

using namespace std;

int n, k, m, a[101010], b[101010], c[101010], noni[101010], ok[1010];
vector<int> ans, ni[101010];
vector<pair<int,int>> v;

int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n >> k >> m;
	for(int i=1; i<=m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		if(c[i] == 0) {
			for(int j=a[i]; j<=b[i]; j++)
				noni[j] = 1;
		} else {
			for(int j=a[i]; j<=b[i]; j++)
				ni[j].push_back(i);
			v.push_back(make_pair(b[i], i));
		}
	}
	sort(v.begin(), v.end());
	for(int i=1; i<=n; i++) {
		if(noni[i])
			continue;
		for(int j=1; j<=n; j++)
			ok[j] = 0;
		int nii = k;
		int vn = -1;
		bool bk = false;
		for(auto u:v) {
			if(vn >= a[u.second])
				continue;
			bool okk = false;
			if(a[u.second] >= i)
				vn = max(vn, i);
			for(int j=u.first; j>=a[u.second]; j--) {
				if(j == i)
					continue;
				if(!noni[j]) 
					vn = j;
					nii--; //
					ok[j] = 1;
					okk = true;
					break;
				}
			}
			if(!okk) {
				bk = true;
				ans.push_back(i);
				continue;
			}
		
		}
		if(bk)
			continue;
		for(int j=1; j<=n; j++) {
			if(nii == 0)
				break;
			if(j == i || ok[j] || noni[j])
				continue;
			nii--;
		}
		if(nii)
			ans.push_back(i);
	}
	if(ans.size() == 0)
		cout << -1;
	sort(ans.begin(), ans.end());
	for(auto u:ans)
		cout << u << "\n";
}