QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#71913#3784. 一行盒子bobo393AC ✓70ms4372kbC++141.9kb2023-01-12 10:32:582023-01-12 10:32:59

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.
  • [2023-01-12 10:32:59]
  • Judged
  • Verdict: AC
  • Time: 70ms
  • Memory: 4372kb
  • [2023-01-12 10:32:58]
  • Submitted

answer

#include <iostream>
#include <cstring>
#include <cstdio>
#include <time.h> 
using namespace std;
const int maxn = 1e5+6;
int *Next,*Per,N,M;
 
void Init()
{
	for(int i=0;i<=N+1;i++)
	{
		Next[i]=i+1;
		Per[i]=i-1;
	}
}
inline void Link1(int x,int y) //put x on the left of y
{
	Next[Per[x]]=Next[x];
	Per[Next[x]]=Per[x];
	Next[x]=y;
	Per[x]=Per[y];
	Next[Per[y]]=x;
	Per[y]=x;
}
inline void Link2(int x,int y) //put x on the right of y
{
	Next[Per[x]]=Next[x];
	Per[Next[x]]=Per[x];
	Next[x]=Next[y];
	Per[x]=y;
	Per[Next[y]]=x;
	Next[y]=x;
}
inline void Link3(int x,int y) //swap a and b 
{
	if(x==Per[y])
	{
		Next[Per[x]]=y;
		Per[Next[y]]=x;
		Per[y]=Per[x];
		Next[x]=Next[y];
		Next[y]=x;
		Per[x]=y;
	}
	else if(x==Next[y])
	{
		Next[Per[y]]=x;
		Per[Next[x]]=y;
		Next[y]=Next[x];
		Per[x]=Per[y];
		Next[x]=y;
		Per[y]=x;
	}
	else
	{
		Next[Per[x]]=y;
		Next[Per[y]]=x;
		int XPE=Per[x],XNE=Next[x],YPE=Per[y],YNE=Next[y];
		Per[y]=XPE;
		Per[x]=YPE;
		Next[x]=YNE;
		Next[y]=XNE;
		Per[XNE]=y;
		Per[YNE]=x;
	}
}
 
int main()
{
	Next=(int *)malloc(sizeof(int)*maxn);
	Per=(int *)malloc(sizeof(int)*maxn);
	int i,j,ty,x,y,cnt,tp,ncase=1;
	while(scanf("%d%d",&N,&M)!=EOF)
	{
		Init();
		cnt=0;
		for(i=1;i<=M;i++)
		{
			scanf("%d",&tp);
			if(tp==1)
			{
				scanf("%d%d",&x,&y);
				if(x==Per[y])
					continue ;
				Link1(x,y);
			}
			else if(tp==2)
			{
				scanf("%d%d",&x,&y);
				if(x==Next[y])
					continue ;
				Link2(x,y);
			}
			else if(tp==3)
			{
				scanf("%d%d",&x,&y);
				Link3(x,y);
			}
			else
			{
				cnt++;
				swap(Next,Per);
			}
		}
		long long ans=0;
		if(cnt&1)
			for(i=Next[N+1];i<=N && i>=1;i=Next[Next[i]])
				ans+=i;
		else
			for(i=Next[0];i<=N && i>=1;i=Next[Next[i]])
				ans+=i;
		printf("Case %d: %lld\n",ncase++,ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 70ms
memory: 4372kb

input:

2 1
3 1 2
10 10
2 3 6
2 10 2
4
3 4 2
2 10 8
1 5 7
3 6 9
3 2 4
4
1 2 3
100 1000
2 12 76
1 6 97
3 80 78
3 23 75
3 88 78
3 48 11
4
4
2 22 89
4
2 60 11
1 92 11
2 39 49
4
4
1 22 47
1 48 14
1 60 58
1 37 40
3 4 36
4
2 39 55
1 62 71
4
1 91 4
4
1 50 49
3 42 29
2 73 47
1 28 93
2 22 97
2 50 32
1 17 38
4
2 8 22...

output:

Case 1: 2
Case 2: 26
Case 3: 2622
Case 4: 10213
Case 5: 2983
Case 6: 2499756727
Case 7: 252019
Case 8: 25055565
Case 9: 2500000000
Case 10: 2500000000

result:

ok 10 lines