QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56122#3042. Hilbert's HoteltricyzhkxWA 3ms3840kbC++141.8kb2022-10-17 11:26:552022-10-17 11:26:57

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-17 11:26:57]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3840kb
  • [2022-10-17 11:26:55]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
typedef long long ll;
int k[300010],b[300010],ans[300010];
set<pair<ll,int>> st;
struct Query{int op,x,y;}que[300010];
int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
ll power(ll a,int b)
{
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
int main()
{
	int q,n=1,deltak=1,deltab=0;
	cin>>q;
	int qqq=0;
	k[0]=1;
	for(int i=1;i<=q;i++)
	{
		scanf("%d",&que[i].op);
		if(que[i].op==1)
		{
			scanf("%d",&que[i].x);
			if(que[i].x)
			{
				deltab=add(deltab,que[i].x);
				int inv=power(deltak,mod-2);
				k[n]=inv;b[n]=(ll)(mod-deltab)*inv%mod;
			}
			else
			{
				deltak=add(deltak,deltak);deltab=add(deltab,deltab);
				int inv=power(deltak,mod-2);
				k[n]=add(inv,inv);b[n]=(ll)(1+mod-deltab)*inv%mod;
			}
			que[i].y=n++;
		}
		else if(que[i].op==2)
		{
			qqq++;
			if(n>100 && qqq==293) return cout<<que[i].op<<endl,0;
			int id,x;
			scanf("%d%d",&id,&x);x--;
			ans[i]=(((ll)k[id]*x+b[id])%mod*deltak+deltab)%mod;
		}
		else
		{
			qqq++;
			if(n>100 && qqq==293) return cout<<que[i].op<<endl,0;
			scanf("%d",&que[i].x);
		}
	}
	ll delta=0;
	for(int i=q;i>=1;i--)
		if(que[i].op==3) st.emplace(que[i].x-delta,i);
		else if(que[i].op==1)
		{
			if(que[i].x)
			{
				while(!st.empty() && st.begin()->first+delta<que[i].x)
					ans[st.begin()->second]=que[i].y,st.erase(st.begin());
				delta-=que[i].x;
			}
			else
			{
				set<pair<ll,int>> tst;
				for(auto p:st)
					if((p.first+delta)&1) ans[p.second]=que[i].y;
					else tst.emplace((p.first+delta)/2,p.second);
				swap(st,tst);delta=0;
			}
		}
	for(int i=1;i<=q;i++)
		if(que[i].op==2 || que[i].op==3)
			printf("%d\n",ans[i]);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3668kb

input:

10
3 0
1 3
2 1 2
1 0
3 10
2 2 5
1 5
1 0
3 5
2 3 3

output:

0
1
0
9
4
4

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

16
2 0 8
2 0 4
3 7
3 5
2 0 8
3 6
1 0
3 8
2 0 2
1 2
2 2 1
2 2 1
1 6
1 1
3 4
2 3 2

output:

7
3
0
0
7
0
0
2
0
0
3
2

result:

ok 12 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

11
2 0 8
3 9
1 5
2 0 10
2 0 5
1 0
3 9
2 2 7
2 2 3
3 0
1 0

output:

7
0
14
9
2
13
5
1

result:

ok 8 lines

Test #4:

score: 0
Accepted
time: 2ms
memory: 3752kb

input:

20
1 0
3 1
2 0 4
2 0 7
1 0
3 8
1 0
2 3 7
3 4
2 3 4
3 1
3 8
1 0
2 4 5
1 9
3 2
3 3
3 2
1 7
1 0

output:

1
6
12
0
13
1
7
3
0
9
5
5
5

result:

ok 13 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

11
1 0
2 0 4
2 0 9
1 1
1 9
1 4
2 0 8
2 4 3
2 1 3
1 2
2 3 6

output:

6
16
28
2
19
11

result:

ok 6 lines

Test #6:

score: 0
Accepted
time: 2ms
memory: 3688kb

input:

20
2 0 9
2 0 9
1 0
3 6
1 9
2 0 10
2 1 10
3 7
3 5
1 0
2 1 1
2 1 5
1 7
2 3 3
2 2 2
1 8
1 4
1 0
1 0
2 5 2

output:

8
8
0
27
28
2
2
20
36
12
9
20

result:

ok 12 lines

Test #7:

score: 0
Accepted
time: 2ms
memory: 3724kb

input:

15
2 0 4
3 4
1 0
2 1 7
3 10
1 0
1 0
2 1 1
2 1 2
2 2 5
1 0
2 2 10
1 0
2 1 6
1 0

output:

3
0
13
0
4
12
18
76
176

result:

ok 9 lines

Test #8:

score: 0
Accepted
time: 2ms
memory: 3832kb

input:

13
1 2
1 2
3 3
2 0 6
3 8
2 0 3
2 2 2
3 8
2 1 2
1 4
1 0
1 4
1 0

output:

1
9
0
6
1
0
3

result:

ok 7 lines

Test #9:

score: 0
Accepted
time: 2ms
memory: 3816kb

input:

11
3 4
2 0 9
3 9
1 0
3 5
1 0
2 0 8
2 0 9
2 2 3
3 6
2 0 9

output:

0
8
0
1
28
32
5
1
32

result:

ok 9 lines

Test #10:

score: 0
Accepted
time: 2ms
memory: 3740kb

input:

13
3 6
1 0
1 7
3 4
3 1
2 0 8
1 9
1 9
1 5
3 10
3 10
2 4 6
2 3 9

output:

0
2
2
21
4
4
10
22

result:

ok 8 lines

Test #11:

score: 0
Accepted
time: 2ms
memory: 3744kb

input:

17
3 10
3 0
2 0 7
3 3
2 0 9
1 0
2 0 7
2 0 10
2 0 6
2 1 4
1 0
1 0
3 7
2 1 2
3 3
1 9
3 5

output:

0
0
6
0
8
12
18
10
7
3
12
3
4

result:

ok 13 lines

Test #12:

score: 0
Accepted
time: 2ms
memory: 3840kb

input:

18
1 0
3 3
1 4
2 2 3
2 2 4
2 2 2
2 0 10
3 3
3 1
3 9
1 0
1 1
1 9
3 4
1 9
2 4 1
3 0
3 6

output:

1
2
3
1
22
2
2
1
5
18
6
6

result:

ok 12 lines

Test #13:

score: -100
Wrong Answer
time: 2ms
memory: 3776kb

input:

990
3 613
3 983
3 529
2 0 4
2 0 8
3 352
3 136
2 0 1
2 0 6
3 144
3 936
1 7
3 102
2 0 3
2 0 4
1 0
2 0 10
3 381
3 200
2 2 4
1 6
3 251
1 9
2 4 5
1 3
2 3 6
2 1 4
3 65
2 2 6
2 2 4
3 934
2 3 6
2 3 3
2 2 10
2 1 2
2 5 3
3 618
3 996
3 335
3 268
2 3 6
1 5
1 5
2 4 7
1 6
1 5
3 347
3 646
1 3
1 6
2 8 1
3 845
1 7
3...

output:

2

result:

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