QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#920587#21403. 文艺平衡树liujiameng#WA 1ms3840kbC++141.0kb2025-02-28 16:44:282025-02-28 16:44:34

Judging History

This is the latest submission verdict.

  • [2025-02-28 16:44:34]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3840kb
  • [2025-02-28 16:44:28]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
mt19937 rnd(844);
int tag[N], rd[N], sz[N], ls[N], rs[N];
void spd(int x){if(tag[x])tag[ls[x]]^=1,tag[rs[x]]^=1,swap(ls[x],rs[x]),tag[x]=0;}
void upd(int x){sz[x]=sz[ls[x]]+sz[rs[x]]+1;}

int merge(int a, int b)
{
	if(!a||!b) return a | b;
	if(rd[a]<rd[b]) return spd(a), rs[a] = merge(rs[a],b), upd(a), a;
	return spd(b), ls[b] = merge(a,ls[b]), upd(b), b;
}

void split(int p, int k, int &x, int &y)
{
	if(!p) return x = y = 0, void();
	spd(p);
	if(sz[ls[p]]<k) x = p, split(rs[p],k-sz[ls[p]]-1,rs[p],y);
	else y = p, split(ls[p],k,x,ls[p]);
	upd(p);
}

void put(int x)
{
	if(!x) return;
	put(ls[x]);
	printf("%d ", x);
	put(rs[x]);
}

int main()
{
	int n, m, i, rt = 0;
	scanf("%d%d", &n, &m);
	for(i=1;i<=n;i++) rd[i] = rnd(), sz[i] = 1, rt = merge(rt,i);
	while(m--)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		int a, b, c;
		split(rt,l-1,a,b);
		split(b,r-l+1,b,c);
		tag[b] ^= 1;
		rt = merge(merge(a,b),c);
	}
	put(rt);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3840kb

input:

30 5
7 26
7 18
5 9
4 15
3 15

output:

1 2 4 5 6 16 15 17 18 19 20 21 22 23 3 24 25 26 14 13 12 9 10 11 8 7 27 28 29 30 

result:

wrong answer 1st lines differ - expected: '1 2 4 17 16 15 6 5 18 19 20 21...4 13 12 11 10 9 8 7 27 28 29 30', found: '1 2 4 5 6 16 15 17 18 19 20 21... 13 12 9 10 11 8 7 27 28 29 30 '