QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#348626#8338. Quad Kingdoms Chessucup-team191#WA 1ms4460kbC++233.2kb2024-03-09 20:05:332024-03-09 20:05:34

Judging History

你现在查看的是最新测评结果

  • [2024-03-09 20:05:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4460kb
  • [2024-03-09 20:05:33]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef vector < int > vi;
typedef vector < pii > vp;

const int N = 1e5 + 500;
const int BUK = 350;
const int MOD = 1e9 + 9;

inline int add(int A, int B) {
	if(A + B >= MOD)
		return A + B - MOD;
	return A + B;
}

inline int sub(int A, int B) {
	if(A - B < 0)
		return A - B + MOD;
	return A - B;
}

inline int mul(int A, int B) {
	return (ll)A * B % MOD;
}

int pos[N], naj[N], pot[N];

void obradi(int l, int r, int n, vi &a, vp &q, vi &spremaj) {
	vector < int > spec;
	for(int i = l;i <= r;i++) spec.PB(q[i].X);
	sort(spec.begin(), spec.end());
	spec.erase(unique(spec.begin(), spec.end()), spec.end());
	for(int x : spec) pos[x] = 1;
	vector < vp > izmedu;
	vp tren;
	int maks = 0;
	for(int i = n - 1;i >= 0;i--) {
		if(pos[i]) {
			izmedu.PB(tren);
			tren.clear();
			naj[i] = maks;
			continue;
		}
		if(a[i] >= maks) {
			tren.PB({a[i], add(tren.empty() ? 0 : tren.back().Y, pot[a[i]])});
			maks = a[i];
		}
	}
	izmedu.PB(tren);
	tren.clear();
	for(int i = l;i <= r;i++) {
		int osn = izmedu[0].empty() ? 0 : izmedu[0].back().Y, tmp_maks = 0;
		a[q[i].X] = q[i].Y;
		for(int i = (int)spec.size() - 1;i >= 0;i--) {
			int x = spec[i];
			if(a[x] >= naj[x] && a[x] >= tmp_maks) {
				osn = add(osn, pot[a[x]]);
			}
			tmp_maks = max(tmp_maks, a[x]);
			int t = (int)spec.size() - i;
			if(!izmedu[t].empty()) {
				if(izmedu[t][0].X >= tmp_maks) {
					osn = add(osn, izmedu[t].back().Y);
				} else if(izmedu[t].back().X < tmp_maks) {
					
				} else {
					osn = add(osn, sub(izmedu[t].back().Y, 
							  (--lower_bound(izmedu[t].begin(), izmedu[t].end(), (pii){tmp_maks, -1}))->Y));
				}
			}
		}
		spremaj.PB(osn);
	}
	for(int x : spec) pos[x] = 0, naj[x] = 0;
}

vi solve(int n, vi &a, vp &q) {
	int poc = 0, maks = 0;
	for(int i = n - 1;i >= 0;i--) {
		if(a[i] >= maks) {
			poc = add(poc, pot[a[i]]);
			maks = a[i];
		}
	}
	vi ret = {poc};
	for(int i = 0;i < (int)q.size();i += BUK)
		obradi(i, min(i + BUK - 1, (int)q.size() - 1), n, a, q, ret);
	//for(int x : a) printf("%d ", x);
	//printf("\n");
	return ret;
}

int n[2], q, ty[2 * N];
vi a[2];
vp svi_q[2];

int main() {
	pot[0] = 1;
	for(int i = 1;i < N;i++)
		pot[i] = mul(pot[i - 1], N + 1);
	scanf("%d", n);
	for(int i = 0;i < n[0];i++) {
		int x; scanf("%d", &x);
		a[0].PB(--x);
	}
	scanf("%d", n + 1);
	for(int i = 0;i < n[0];i++) {
		int x; scanf("%d", &x);
		a[1].PB(--x);
	}
	scanf("%d", &q);
	for(int i = 0;i < q;i++) {
		scanf("%d", ty + i); ty[i]--;
		int x, y; scanf("%d%d", &x, &y);
		x--; y--;
		svi_q[ty[i]].PB({x, y});
	}
	//vi odg[2] = {solve(n[0], a[0], svi_q[0]), solve(n[1], a[1], svi_q[1])};
	vi odg[2];
	odg[0] = solve(n[0], a[0], svi_q[0]);
	odg[1] = solve(n[1], a[1], svi_q[1]);
	int ind[2] = {0, 0};
	for(int j = 0;j < q;j++) {
		ind[ty[j]]++;
		//printf("%d %d\n", odg[0][ind[0]], odg[1][ind[1]]);
		printf(odg[0][ind[0]] == odg[1][ind[1]] ? "YES\n" : "NO\n");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4460kb

input:

5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5

output:

NO
NO
NO
YES
NO
NO
NO
YES

result:

ok 8 tokens

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 4232kb

input:

1
2
6
2 1 1 1 1 1
200000
2 6 2
1 1 1
1 1 1
1 1 2
2 1 1
1 1 2
1 1 1
2 4 1
2 1 2
1 1 1
1 1 2
2 5 1
1 1 1
1 1 2
1 1 1
2 6 1
1 1 2
1 1 2
1 1 2
2 3 1
1 1 1
2 1 1
2 6 2
1 1 2
2 4 1
1 1 2
2 6 1
1 1 2
1 1 1
2 5 2
2 6 2
1 1 1
2 4 2
2 5 2
2 6 2
1 1 1
2 5 1
2 6 2
1 1 2
1 1 1
1 1 1
2 4 1
1 1 2
1 1 2
1 1 2
2 3 2...

output:

NO

result:

wrong answer Unexpected EOF in the participants output