QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67111#5098. 第一代图灵机yehaodee20 141ms13288kbC++143.5kb2022-12-10 09:27:502022-12-10 09:27:52

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 09:27:52]
  • Judged
  • Verdict: 20
  • Time: 141ms
  • Memory: 13288kb
  • [2022-12-10 09:27:50]
  • 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
int main() {
#ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
#endif
	read(n, m, q);
	for (int i = 1; i <= n; i++) read(a[i]), sum[i] = sum[i - 1] + 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; }
	return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 31ms
memory: 3596kb

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:

118571
90725
79596
95154
95154
94493
72411
100567
100567
100567
100567
90725
100567
100567
90725
118571
94493
95154
58191
118571
100567
100567
100567
39374
89208
118571
99923
100567
100567
95724
87252
100567
118571
100567
100567
100567
100567
100567
100567
26617
100567
99923
100567
118571
100567
100...

result:

ok 3799 lines

Test #2:

score: 0
Accepted
time: 28ms
memory: 3708kb

input:

5000 1000 5000
451 521 3465 4281 3422 1186 2547 3341 2060 1467 717 2115 2513 2471 1399 1812 3070 2173 521 1621 2801 4020 4493 138 4162 97 1179 171 4011 3340 2393 689 1830 3981 2352 3352 3561 2969 1037 1205 2390 3916 1578 2313 2433 885 1097 1820 739 4483 3241 3861 1547 665 1449 4133 4877 1005 3510 18...

output:

188595
209663
209663
209663
209663
209663
209282
209663
209663
176195
156041
141623
176195
209663
209663
209282
175706
209663
209663
209663
209663
209663
209282
209663
209663
209663
188595
209282
209663
183686
209663
163197
209663
183686
209663
183686
209663
175706
209663
209663
209663
209663
209663...

result:

ok 3724 lines

Subtask #2:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 137ms
memory: 13288kb

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:

1232419
1222519
1232419
1232419
1232419
1232419
1232419
1232419
1232419
1232419
1040511
1148070
1232419
1232419
1232419
1232419
1206368
1206368
1232419
1232419
1232419
1222519
1167757
1206368
1214212
1222519
1232419
1222519
1222519
1160928
1011843
1232419
1232419
1189403
1222519
1232419
1222519
1148...

result:

ok 150001 lines

Test #4:

score: 0
Accepted
time: 141ms
memory: 13120kb

input:

200000 10 200000
30667 76440 31754 172209 119166 184237 184837 164501 15853 166011 36513 137215 94697 78289 80876 166026 32881 92643 80793 147949 182785 165617 115046 182305 83873 100693 190096 140639 74339 167389 43600 107001 37622 20476 13072 47637 49833 39017 93821 44733 195599 196124 58413 19221...

output:

1373616
1224613
1269269
1105924
1211028
1128748
1373616
1285605
1373616
1373616
1317624
1317624
1373616
1317624
1187052
1373616
1373616
1317624
1317624
1187052
1126035
1317624
1131579
1269269
1317624
1169493
1317624
1317624
1285605
1373616
1069964
1373616
1373616
1373616
1373616
1317624
1373616
1373...

result:

ok 150029 lines

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 4ms
memory: 7412kb

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:

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

Subtask #4:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #9:

score: 0
Wrong Answer
time: 4ms
memory: 5072kb

input:

50000 1000 50000
22098 40691 15626 6766 15467 15377 43375 7991 25841 6053 2031 38833 19761 42385 9421 28399 42001 15985 31206 30047 14001 7441 8377 5217 4402 37695 41393 25926 38137 32913 23203 31265 31401 32772 32905 24167 5233 24058 41685 26999 41 18461 15721 49365 49676 3151 29237 22894 37323 272...

output:


result:

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

Subtask #5:

score: 0
Skipped

Dependency #4:

0%