QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67186#5098. 第一代图灵机_ZMF_30 468ms55588kbC++113.4kb2022-12-10 10:28:462022-12-10 10:28:50

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 10:28:50]
  • Judged
  • Verdict: 30
  • Time: 468ms
  • Memory: 55588kb
  • [2022-12-10 10:28:46]
  • Submitted

answer

/*
60 + 0 + 100 + 64 = 224.
*/

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
	int sum = 0, nega = 1;
	char ch = getchar();
	while (ch > '9'||ch < '0')
	{
	    if (ch == '-') nega = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
	return sum * nega;
}
// 真不会写线段树维护单调栈/ng 
const int N = 2e5 + 9;
int n, m, q, a[N], c[N], nxt[N], sum[N], Lim;
set<int> s[N];
int mn[N << 2], tr[N << 2];
inline int lc(int p) {return p << 1;}
inline int rc(int p) {return p << 1 | 1;}
inline int query(int l, int r, int p, int v) 
{
	if(mn[p] > v) return 0;
	if(l == r) return sum[v - 1] - sum[l];
	int mid = (l + r) >> 1;
	if(mn[rc(p)] >= v) return query(l, mid, lc(p), v);
	else return max(tr[p], query(mid + 1, r, rc(p), v));
}
inline void push_up(int l, int r, int p) 
{
	mn[p] = min(mn[lc(p)], mn[rc(p)]);
	int mid = (l + r) >> 1;
	tr[p] = query(l, mid, lc(p), mn[rc(p)]); 
	return ;
}
inline void build(int l, int r, int p) 
{
	if(l == r) {mn[p] = nxt[l]; tr[p] = 0; return ;}
	int mid = (l + r) >> 1; 
	build(l, mid, lc(p)); build(mid + 1, r, rc(p));
	push_up(l, r, p); return ;
}
inline void update(int l, int r, int p, int pos) 
{
	if(pos == 0) return ;
	if(l == r) {mn[p] = nxt[l]; tr[p] = 0; return ;}
	int mid = (l + r) >> 1; 
	if(mid >= pos) update(l, mid, lc(p), pos);
	else update(mid + 1, r, rc(p), pos);
	push_up(l, r, p); return ;
}
inline int get(int l, int r, int p, int L, int R)
{
	if(l == r) return mn[p];
	int mid = (l + r) >> 1; 
	int res = 1e9;
	if(mid >= L) res = min(res, get(l, mid, lc(p), L, R));
	if(mid < R) res = min(res, get(mid + 1, r, rc(p), L, R));
	return res;
}
inline int Query(int l, int r, int p, int L, int R) 
{
	int res = 0;
	if(L <= l && r <= R) 
	{
		res = query(l, r, p, Lim); Lim = min(Lim, mn[p]);
		return res;
	}
	int mid = (l + r) >> 1;
	if(mid < R) res = max(res, Query(mid + 1, r, rc(p), L, R));
	if(mid >= L) res = max(res, Query(l, mid, lc(p), L, R));
	return res;
}
signed main()
{
	n = read(), m = read(), q = read();
	for (int i = 1; i <= n; i++) a[i] = read(), sum[i] = sum[i - 1] + a[i];
	for (int i = 1; i <= n; i++) s[i].insert(n + 1), s[i].insert(0);
	for (int i = 1; i <= n; i++) c[i] = read(), s[c[i]].insert(i);
	for (int i = 1; i <= n; i++) nxt[i] = *s[c[i]].upper_bound(i);
	build(1, n, 1);
	for (int i = 1; i <= q; i++) 
	{
		int opt = read();
		if(opt == 1) 
		{
			int l = read(), r = read(); Lim = r + 1;
			int ans = Query(1, n, 1, l, r);
			int now = 1e9; 
			bool flag = 0;
			for (int j = l; j <= r; j++) 
			{
				if(j >= now) {flag = 1; ans = max(ans, sum[j - 1] - sum[l - 1]); break;} 
				now = min(now, nxt[j]);
			}
			for (int j = r; j >= l; j--) 
			{
				if(nxt[j] <= r) break; 
				ans = max(ans, sum[r] - sum[j - 1]);
			}
			if(!flag) ans = max(ans, sum[r] - sum[l - 1]);
			printf("%lld\n", ans);
		}
		else 
		{
			int pos = read(), col = read();
			if(c[pos] == col) continue;
			int pre1 = *(--s[c[pos]].lower_bound(pos));
			int pre2 = *(--s[col].lower_bound(pos));
			s[c[pos]].erase(pos); 
			s[col].insert(pos); 
			c[pos] = col;
			nxt[pre1] = nxt[pos]; nxt[pos] = nxt[pre2]; nxt[pre2] = pos;
			update(1, n, 1, pre1); update(1, n, 1, pre2); update(1, n, 1, pos); 
		}
	}
	return 0;
}


详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 9ms
memory: 14112kb

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:

wrong answer 307th lines differ - expected: '92305', found: '77192'

Subtask #2:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 442ms
memory: 55484kb

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: 437ms
memory: 55588kb

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: 20
Accepted

Test #5:

score: 20
Accepted
time: 391ms
memory: 55500kb

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:

46702944
46702944
38383720
38615532
38615532
42801975
39035571
46702944
46702944
46702944
27438528
38402892
46702944
46702944
42801975
42323113
39035571
42323113
46702944
46702944
46702944
41821993
46702944
34075405
46702944
38615532
46702944
28680653
46702944
42801975
42801975
38025842
46702944
467...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 404ms
memory: 55552kb

input:

200000 20000 200000
35105 74665 63960 162062 164953 63344 145369 115837 108866 61866 110690 123641 106889 65531 115933 163273 7531 128251 158561 169221 149787 40911 54465 92737 73473 10609 62701 89599 40007 40272 7318 129047 171198 90131 111281 85645 174001 140289 135851 26785 136485 31989 16313 888...

output:

43816163
35764822
45394839
45394839
45394839
43816163
45394839
43816163
40900280
38802753
45394839
45394839
43816163
34715395
45394839
43816163
43816163
45394839
43816163
45394839
45394839
43816163
35764822
45394839
43816163
43816163
16638306
45394839
35764822
45394839
34921501
45394839
45394839
409...

result:

ok 200000 lines

Test #7:

score: 0
Accepted
time: 441ms
memory: 55480kb

input:

200000 20000 200000
80203 178041 44172 21001 54489 120807 60663 147301 166763 49071 98913 115641 30627 164382 54165 165057 46105 9628 57953 86346 8273 137848 44871 119728 107309 132201 72483 198451 58505 185062 27039 49401 172444 101505 180973 59256 44859 53105 195233 161425 132423 2566 189331 15869...

output:

44318499
33827474
43556508
44318499
43556508
38914187
44318499
43556508
47858466
44318499
40709211
43556508
35706654
43556508
44318499
44318499
47858466
44318499
35359541
43556508
43556508
43556508
47858466
31755901
43556508
44318499
43556508
43556508
44318499
44318499
44318499
44318499
43556508
443...

result:

ok 200000 lines

Test #8:

score: 0
Accepted
time: 468ms
memory: 55504kb

input:

200000 20000 200000
69757 155771 81753 9285 168151 179881 122502 198324 140481 33185 155861 173423 117211 80727 63754 167913 121921 185921 182266 24801 167005 191511 77176 176741 117041 42534 10209 6241 83970 67652 164225 155249 125057 23841 71911 133150 79732 125061 7111 29841 142343 129299 155501 ...

output:

54623112
54623112
54623112
36983972
41889300
49604086
43664569
54623112
42438674
39404039
43664569
35418806
43664569
54623112
49604086
49604086
42438674
54623112
54623112
33869050
54623112
42438674
36847615
39404039
54623112
54623112
43664569
49604086
42438674
54623112
54623112
43664569
49604086
424...

result:

ok 200000 lines

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%