제출 #1337478

#제출 시각아이디문제언어결과실행 시간메모리
1337478penguin133Kraljica (COCI25_kraljica)C++20
0 / 110
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct node{
	int s, e, m, val, lz;
	node *l, *r;
	node (int _s, int _e){
		s = _s, e = _e, m = (s + e) >> 1;
		if (s != e) l = new node(s, m), r = new node (m + 1, e);
		val = 0;
		lz = -1;
	}
	
	void prop(){
		if (lz != -1) {
			val = lz * (e - s + 1);
			if (s != e) l->lz = lz, r->lz = lz;
			lz = -1;
		}
	}
	
	void upd (int a, int b, int c){
		if (a > b) return;
		prop();
		if (a == s && b == e) lz = c;
		else {
			if (b <= m) l->upd(a, b, c);
			else if (a > m) r->upd(a, b, c);
			else l->upd(a, m, c), r->upd(m + 1, b, c);
			l->prop(), r->prop();
			val = l->val + r->val;
		}
	}
	
	int qry(int a, int b){
		if (a > b) return 0;
		prop();
		if (a == s && b == e) return val;
		else if (b <= m) return l->qry(a, b);
		else if (a > m) return r->qry(a, b);
		else return l->qry(a, m) + r->qry(m + 1, b);
	}
}*odd, *even;

void solve(){
	int n, q, k;
	cin >> n >> q >> k;
	odd = new node(1, n + 4);
	even = new node(1, n + 4);
	int pos = 0;
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		if (x == k) pos = i;
		if (i & 1) {
			if (x <= k) odd->upd((i + 1) / 2, (i + 1) / 2, 1);
		}
		else {
			if (x <= k) even->upd(i / 2, i / 2, 1);
		}
	}
	while (q--) {
		int l, r; cin >> l >> r;
		bool f = 0;
		if (l <= pos && pos <= r)f = 1;
		if (0) {
			
		}
		else {
			int num1 = odd->qry(l / 2 + 1, (r + 1) / 2) + even->qry((l + 1) / 2, r / 2);
			//cout << odd->qry(l / 2 + 1, (r + 1) / 2) << ' ';
			//cout << num1 << ' ';
			//assert(num1 == f || num1 == r - l + 1);
			assert(num1 >= 0 && num1 <= r - l + 1);
			if (l & 1) {
				int od = (r - l + 1 + 1) / 2;
				if (num1 <= od) {
					odd->upd(l / 2 + 1, l / 2 + num1, 1);
					odd->upd(l / 2 + 1 + num1, (r + 1) / 2, 0);
					even->upd((l + 1) / 2, r / 2, 0);
					if (f) pos = l + (num1 - 1) * 2;
				}
				else {
					odd->upd(l / 2 + 1, (r + 1) / 2, 1);
					num1 -= od;
					
					even->upd(r / 2 - num1 + 1, r / 2, 1);
					even->upd((l + 1) / 2, r / 2 - num1, 0);
					
					//even->upd((l + 1) / 2, r / 2, 1);
					if (f) pos = ((r & 1) ? r - 1 : r) - (num1 - 1) * 2;
				}
			}
			else {
				int od = (r - l + 1 + 1) / 2;
				if (num1 <= od) {
					even->upd((l + 1) / 2, (l + 1) / 2 + num1 - 1, 1);
					even->upd((l + 1) / 2 + num1, r / 2, 0);
					odd->upd(l / 2 + 1, (r + 1) / 2, 0);
					if (f) pos = l + (num1 - 1) * 2;
				}
				else {
					even->upd((l + 1) / 2, r / 2, 1);
					num1 -= od;
					
					odd->upd((r + 1) / 2 - num1 + 1, (r + 1) / 2, 1);
					odd->upd(l / 2 + 1, (r + 1) / 2 - num1, 0);
					
					//odd->upd(l / 2 + 1, (r + 1) / 2, 1);
					if (f) pos = ((r & 1) == 0 ? r - 1 : r) - (num1 - 1) * 2;
				}
			}
		}
		if (f) assert (l <= pos && pos <= r);
		//cerr << pos << '\n';
	}
	cout << pos;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:129:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  129 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...