QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67205#5098. 第一代图灵机_ZMF_0 451ms55552kbC++113.2kb2022-12-10 10:39:372022-12-10 10:39:58

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:39:58]
  • Judged
  • Verdict: 0
  • Time: 451ms
  • Memory: 55552kb
  • [2022-12-10 10:39:37]
  • 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 = min(res, Query(mid + 1, r, rc(p), L, R));
	if(mid >= L) res = min(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 = min(r + 1, get(1, n, 1, l, r));
			int now = r + 1;
			ans = max(ans, sum[now - 1] - 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); 
			nxt[pre1] = *s[c[pos]].upper_bound(pre1); 
			nxt[pos] = *s[col].upper_bound(pos); 
			nxt[pre2] = *s[col].upper_bound(pre2);
			c[pos] = col;
			update(1, n, 1, pre1); update(1, n, 1, pre2); update(1, n, 1, pos); 
		}
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 14184kb

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:

6757775
4243316
995668
3883864
3852532
839886
799332
3760893
6560417
6602222
4368163
3963224
4043984
5640952
304544
2024983
823142
310042
277635
3329623
6770353
4615419
6541567
39374
1695239
6318699
437547
3506869
3257847
1157887
1292061
2376254
7699122
7121536
6032182
3793285
9801876
2872902
750734...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 451ms
memory: 55552kb

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:

14520254940
3010209214
3092101237
4121673130
10593308866
14836410249
14042523465
10454328173
2829467170
16088138330
156846664
691884844
13168003042
11618785689
15869628828
9622247828
4998552257
683067340
7604179307
13314628628
12595954289
5290547225
4767632013
3799281876
2602008002
3586800479
136897...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 316ms
memory: 55508kb

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:

6621858508
13369763706
931223557
2620475833
750333254
9534954289
3005023565
9839704978
13389325043
2836756946
125441385
547086620
3319086817
13401822199
12306023090
3918645481
4220592768
4196673580
17911564462
4642753825
12144192684
5386259737
3380344537
1694960013
11951325862
2557945957
14743220752...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%