QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67380#5098. 第一代图灵机yehaodee0 911ms9936kbC++145.9kb2022-12-10 12:19:172022-12-10 12:19:49

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 12:19:49]
  • Judged
  • Verdict: 0
  • Time: 911ms
  • Memory: 9936kb
  • [2022-12-10 12:19:17]
  • Submitted

answer

#include <bits/stdc++.h>
namespace IO {
#define iL (1 << 20)
char ibuf[iL], *iS = ibuf + iL, *iT = ibuf + iL;
#define gc() ((iS == iT) ? (iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin), iS == iT ? EOF : *iS ++) : *iS ++)
template<class T> inline void read(T &x) {
	x = 0;int f = 0;char ch = gc();
	for (; !isdigit(ch); f |= ch == '-', ch = gc());
	for (; isdigit(ch); x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc());
	x = (f == 1 ? ~ x + 1 : x);
}
template<class T, class... Args> inline void read(T &x, Args&... args) { read(x), read(args...); }
template<class T> inline void readch(T &x) { char ch = gc(); for (; !isalpha(ch); ch = gc()); x = ch; }
char Out[iL], *iter = Out;
#define flush() fwrite(Out, 1, iter - Out, stdout), iter = Out
template<class T> inline void write(T x, char ch = '\n') {
	T l, c[35];
	if (x < 0) *iter ++ = '-', x = ~ x + 1;
	for (l = 0; !l || x; c[l] = x % 10, l++, x /= 10);
	for (; l; -- l, *iter ++ = c[l] + '0');*iter ++ = ch;
	flush();
}
} // IO
using namespace IO;
#define N 200005
#define ll long long
#define DEBUG
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
int n, m, q, a[N], c[N]; ll sum[N];
namespace sub1 {
#define kN 5005
void main() {
	for (int _ = 1, op, x, y; _ <= q; _++) {
		read(op, x, y); static int buc[kN]; for (int i = 1; i <= m; i++) buc[i] = 0;
		if (op == 1) {
			int R = x; buc[c[x]] ++; ll ans = 0;
			for (int i = x; i <= y; i++) {
				while (R < y && !buc[c[R + 1]]) { R ++; buc[c[R]] ++; }
				ans = max(ans, sum[R] - sum[i - 1]); buc[c[i]] --;
			}
			write(ans);
		}  else c[x] = y;
	}
}
} // sub1
namespace sub2 {
ll hans[N], mx[N * 4];
void modify(int k, int l, int r, int x, ll v) {
	if (l == r) { mx[k] = v; return ; }
	int mid = l + r >> 1;
	(x <= mid) ? modify(k << 1, l, mid, x, v) : modify(k << 1 | 1, mid + 1, r, x, v);
	mx[k] = max(mx[k << 1], mx[k << 1 | 1]);
}
int query(int k, int l, int r, int x, int y) {
	if (x <= l && r <= y) return mx[k];
	if (x > r || l > y) return 0;
	int mid = l + r >> 1; return max(query(k << 1, l, mid, x, y), query(k << 1 | 1, mid + 1, r, x, y));
}
void main() {
	for (int i = 1; i <= n; i++) {
		static int buc[15]; memset(buc, 0, sizeof buc);
		int R = i; buc[c[i]] ++;
		while (R < n && !buc[c[R + 1]]) { R ++; buc[c[R]] ++; }
		hans[i] = sum[R] - sum[i - 1]; modify(1, 1, n, i, hans[i]);
	}
	for (int _ = 1, op, x, y; _ <= q; _++) {
		read(op, x, y);
		if (op == 1) {
			int pl = max(y - m + 1, x); ll ans = 0;
			if (x < pl) ans = query(1, 1, n, x, pl - 1);
			for (int i = pl; i <= y; i++) {
				static int buc[15]; memset(buc, 0, sizeof buc);
				int R = i; buc[c[i]] ++;
				while (R < y && !buc[c[R + 1]]) { R ++; buc[c[R]] ++; }
				ans = max(ans, sum[R] - sum[i - 1]);
			}
			write(ans);
		}  else  {
			c[x] = y;
			int pl = max(x - m + 1, 1);
			for (int i = pl; i <= x; i++) {
				static int buc[15]; memset(buc, 0, sizeof buc);
				int R = i; buc[c[i]] ++;
				while (R < n && !buc[c[R + 1]]) { R ++; buc[c[R]] ++; }
				hans[i] = sum[R] - sum[i - 1]; modify(1, 1, n, i, hans[i]);
			}
		}
	}
}
} // sub2
namespace sub3 {
ll sum[N * 4], mx[N * 4];
void modify(int k, int l, int r, int x, ll v) {
	if (l == r) { sum[k] = mx[k] = v; return ; }
	int mid = l + r >> 1;
	(x <= mid) ? modify(k << 1, l, mid, x, v) : modify(k << 1 | 1, mid + 1, r, x, v);
	sum[k] = (sum[k << 1] + sum[k << 1 | 1]); mx[k] = max(mx[k << 1], mx[k << 1 | 1]);
}
ll query(int k, int l, int r, int x, int y) {
	if (x <= l && r <= y) return sum[k];
	if (x > r || l > y) return 0;
	int mid = l + r >> 1; return query(k << 1, l, mid, x, y) + query(k << 1 | 1, mid + 1, r, x, y);
}
ll querymax(int k, int l, int r, int x, int y) {
	if (x <= l && r <= y) return mx[k];
	if (x > r || l > y) return 0;
	int mid = l + r >> 1; return max(querymax(k << 1, l, mid, x, y), querymax(k << 1 | 1, mid + 1, r, x, y));
}
struct node { int l, r, c; };
bool operator < (node a, node b) { return a.l < b.l; }
set<node> odt;
#define IT set<node>::iterator
IT split(int x) {
	auto it = odt.lower_bound((node){x, 0, 0});
	if (x > n) return odt.end(); 
	if (it != odt.end() && it->l == x) return it;
	it --; if (it->r < x) return odt.end();
	int L = it->l, R = it->r, C = it->c; odt.erase(it);
	odt.insert((node){L, x - 1, C});
	return odt.insert((node){x, R, C}).fi;
}
IT assign(int l, int r, int c) {
	auto itr = split(r + 1); auto itl = split(l);
	odt.erase(itl, itr); return odt.insert((node){l, r, c}).fi;
}
void push(IT it) {
	auto itl = it, itr = it;
	while (itl != odt.begin() && itl->c == it->c) itl --; if (itl->c != it->c) itl ++;
	while (itr != odt.end() && itr->c == it->c) itr ++; itr --;
	if (itl != itr) assign(itl->l, itr->r, itl->c);
}
void main() {
	for (int i = 1; i <= n; i++) {
		modify(1, 1, n, i, a[i]); 
		auto it = odt.insert((node){i, i, c[i]}).fi; push(it);
		// for (auto it : odt) write(it.l, ' '), write(it.r, ' '), write(it.c);
	}
	for (int _ = 1, op, x, y; _ <= q; _++) {
		read(op, x, y);
		if (op == 1) {
			unordered_map<int, int> col; ll ans = querymax(1, 1, n, x, y); col.clear();
			auto itr = split(y + 1), itl = split(x); auto R = itl;
			for (; R != itr; R ++) {
				col[R->c] ++;
				while (itl != R && col[R->c] > 1) { col[itl->c] --; itl ++; }
				if (itl != R) ans = max(ans, query(1, 1, n, itl->r, R->l));
				if (R->l != R->r) { 
					while (itl != R) { col[itl->c] --; itl ++; } 
					col[R->c] --;
				}
			}
			write(ans);
		}  else {
			auto it = assign(x, x, y); push(it);
		}
	}
}
} // sub3
int main() {
#ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
#endif
	// freopen("a.in", "r", stdin); freopen("a.out", "w", stdout);
	read(n, m, q);
	for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= n; i++) read(c[i]);
	// if (n <= 5000 && q <= 5000) { sub1::main(); return 0; }
	// if (m <= 10) { sub2::main(); return 0; }
	sub3::main();
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 911ms
memory: 9936kb

input:

5000 200 5000
2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...

output:

127909
95470
79596
105783
105783
94493
72411
117226
117226
117226
100567
95470
100567
117226
90725
118571
94493
95154
58191
118571
117226
105783
117226
39374
90983
127909
99923
100567
117226
95724
87252
100567
127909
117226
117226
100567
118211
100567
117226
26617
117226
115203
117226
118571
105783
...

result:

wrong answer 1st lines differ - expected: '118571', found: '127909'

Subtask #2:

score: 0
Time Limit Exceeded

Test #3:

score: 0
Time Limit Exceeded

input:

200000 10 200000
55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded

input:

200000 20000 200000
30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%