QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#718001#5188. 鬼街Southern_DynastyAC ✓5194ms933116kbC++173.6kb2024-11-06 19:28:422024-11-06 19:28:44

Judging History

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

  • [2024-11-06 19:28:44]
  • 评测
  • 测评结果:AC
  • 用时:5194ms
  • 内存:933116kb
  • [2024-11-06 19:28:42]
  • 提交

answer

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define gt getchar
#define pt putchar
#define fst first
#define scd second
#define SZ(s) ((int)s.size())
#define all(s) s.begin(),s.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
const int N=1e5+5;
using namespace std;
using namespace __gnu_pbds;
typedef pair<ll,int> pii;
template<class T,class I> inline bool chkmax(T &a,I b){return b>a?a=b,1:0;}
template<class T,class I> inline bool chkmin(T &a,I b){return b<a?a=b,1:0;}
inline bool __(char ch){return ch>=48&&ch<=57;}
template<class T> inline void read(T &x){
	x=0;bool sgn=0;static char ch=gt();
	while(!__(ch)&&ch!=EOF) sgn|=(ch=='-'),ch=gt();
	while(__(ch)) x=(x<<1)+(x<<3)+(ch&15),ch=gt();
	if(sgn) x=-x;
}
template<class T,class ...I> inline void read(T &x,I &...x1){
	read(x);
	read(x1...);
}
template<class T> inline void print(T x){
	static char stk[70];short top=0;
	if(x<0) pt('-');
	do{stk[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
	while(top) pt(stk[top--]);
}
template<class T> inline void printsp(T x){
	print(x);
	putchar(' ');
}
template<class T> inline void println(T x){
	print(x);
	putchar('\n');
}
int n,m,lst,tim[N];
vector<int> fac[N];
ll tag[N];// 减了多少.
struct item{
	ll val;
	int pos,tim;
	item(ll _val=0,int _pos=0,int _tim=0)
		:val(_val),pos(_pos),tim(_tim)
	{}
	inline bool operator>(const item &b)const{
		return val>b.val;
	} 
};
priority_queue<item,vector<item>,greater<item> > pq[N];
struct Node{
	int k,vec[10];
	ll lim,now[10];
	inline void input(){
		read(lim);
		k=SZ(fac[lim]);
		for(int i=1;i<=k;++i) vec[i]=fac[lim][i-1];
		read(lim);
		lim^=lst;
	}
	inline ll calc(){
		ll ans=0;
		for(int i=1;i<=k;++i) ans+=now[i]-tag[vec[i]];
		return ans;
	}
}node[N];
inline void upd(int x,ll y,vector<int> &ans){
	tag[x]+=y;
	while(SZ(pq[x])&&pq[x].top().val-tag[x]<=0){
		int u=pq[x].top().pos;
		if(pq[x].top().tim!=tim[u]){
			pq[x].pop();
			continue;
		}
		ll cur=node[u].calc();
		if(cur<=0){
			ans.eb(u);
			tim[u]++;
		}else{
			tim[u]++;
			for(int i=1;i<=node[u].k;++i) node[u].now[i]=cur/node[u].k;
			cur%=node[u].k;
			for(int i=1;i<=node[u].k&&cur;++i){
				if(node[u].vec[i]==x){
					node[u].now[i]++;
					cur--;
					break;
				}	
			}
			for(int i=1;i<=node[u].k&&cur;++i){
				if(node[u].vec[i]!=x){
					node[u].now[i]++;
					cur--;
				}
			}
			for(int i=1;i<=node[u].k;++i){
				int id=node[u].vec[i];
				node[u].now[i]+=tag[id];
				pq[id].push(item(node[u].now[i],u,tim[u]));
			}
		}
	}
}	
signed main(){
	read(n,m);
	for(int i=2;i<=n;++i){
		if(!SZ(fac[i])){ 
			for(int j=i;j<=n;j+=i) fac[j].eb(i);
		}
	}
	vector<int> zero;
	int tot=0;
	for(ll opt,x,y;m;--m){
		read(opt);
		if(opt==1){
			node[++tot].input();
			if(!node[tot].lim){
				zero.eb(tot);
				continue;
			}
			for(int i=1;i<=node[tot].k;++i){
				node[tot].now[i]=(node[tot].lim/node[tot].k);
			}
			for(int i=1;i<=node[tot].lim%node[tot].k;++i) node[tot].now[i]++;
			for(int i=1;i<=node[tot].k;++i){
				int id=node[tot].vec[i];
				node[tot].now[i]+=tag[id];
				pq[id].push(item(node[tot].now[i],tot,0));
			}
		}else{
			read(x,y);
			y^=lst;
			vector<int> ans;
			for(int v:fac[x]) upd(v,y,ans);
			for(int v:zero) ans.eb(v);
			zero.clear();
			sort(all(ans));
			lst=SZ(ans);
			print(lst);
			for(int v:ans) pt(' '),print(v);
			printf("\n");
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 10608kb

input:

20 9
1 10 2
0 5 0
0 6 1
0 7 1
0 15 1
1 12 3
0 8 0
1 5 0
0 8 2

output:

0
0
0
1 1
0
2 2 3

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 4ms
memory: 10940kb

input:

5000 5000
1 308 2924116129
1 3201 931426424
1 4398 709387999
0 609 2256581248
0 1566 1777416018
1 4709 1171183682
0 3770 752123966
1 1896 3894906376
0 230 3761076141
1 1345 676968476
1 3116 342409501
0 4948 3143999592
1 2186 2376352094
1 3892 3478048443
0 2773 2100852395
1 2894 2317216575
0 3378 211...

output:

2 2 3
1 1
0
0
2 5 7
0
0
0
1 11
1 4
3 8 9 10
0
0
0
5 13 14 15 17 19
0
0
2 18 20
0
2 16 22
5 6 21 23 24 25
0
0
2 27 29
1 28
2 26 30
0
0
0
0
0
0
1 33
0
0
2 31 32
0
0
2 35 36
0
0
1 37
0
0
0
0
1 39
1 40
0
0
1 42
0
0
2 34 43
0
0
4 44 46 48 49
2 50 51
0
0
1 52
0
2 45 53
0
0
0
3 54 56 59
2 57 61
0
0
0
0
0
0...

result:

ok 2569 lines

Test #3:

score: 0
Accepted
time: 38ms
memory: 22948kb

input:

100000 100000
0 88257 3347892307
1 75731 1809061227
0 16838 427131616
1 37901 3913929645
0 34652 2841091466
1 94967 1193577995
0 88669 2312699947
0 65963 2968268361
0 24727 3935129828
0 85199 4076952986
0 80409 4193957044
1 65125 3928747142
1 46471 976433442
0 40164 1210148974
0 66889 3862378511
1 5...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
2 7 8
1 9
0
1 12
1 11
2 10 13
6 4 15 16 18 20 21
1 23
0
1 17
0
0
0
1 30
0
0
1 24
0
5 26 28 31 32 34
1 36
1 37
0
0
4 27 29 38 39
2 40 42
5 3 43 45 47 48
2 33 41
1 46
3 49 50 51
0
0
1 52
3 14 44 54
0
0
0
0
0
0
0
3 57 58 60
0
11 55 56 62 63 65 66 67 68 69 70 71
0
0
1 72
0
0
3 ...

result:

ok 49859 lines

Test #4:

score: 0
Accepted
time: 206ms
memory: 31796kb

input:

100000 100000
1 100000 686376074
1 99999 1480169272
1 99998 3342696633
1 99997 3780400597
1 99996 987312141
1 99995 1940629988
1 99994 3882419811
1 99993 2620287406
1 99992 117147645
1 99991 4118056210
1 99990 1544011251
1 99989 2856008809
1 99988 1621361290
1 99987 3983397497
1 99986 1989759776
1 9...

output:

37 1777 4119 4466 7328 10001 10481 10796 11973 13694 13747 17453 18447 18452 18710 24307 24353 27219 27867 31925 32241 32807 35929 36485 36515 36920 37737 38555 39865 40243 41097 42861 44559 44895 45518 45572 48590 48809
30 2625 3410 4325 4643 4785 10441 13124 16215 19575 23229 24815 27493 29907 301...

result:

ok 50000 lines

Test #5:

score: 0
Accepted
time: 261ms
memory: 90120kb

input:

100000 100000
1 2 50000
1 4 50000
1 6 50000
1 8 50000
1 10 50000
1 12 50000
1 14 50000
1 16 50000
1 18 50000
1 20 50000
1 22 50000
1 24 50000
1 26 50000
1 28 50000
1 30 50000
1 32 50000
1 34 50000
1 36 50000
1 38 50000
1 40 50000
1 42 50000
1 44 50000
1 46 50000
1 48 50000
1 50 50000
1 52 50000
1 54...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 50000 lines

Test #6:

score: 0
Accepted
time: 25ms
memory: 22644kb

input:

100000 100000
1 71533 1624315381
0 89184 1624315381
1 93680 3158643236
0 66680 3158643236
1 93948 1261724001
0 59949 1261724001
1 42374 1643731476
0 84748 1643731476
1 88256 2309789107
0 38136 2309789107
1 51927 2589008727
0 91100 2589008727
1 37451 2981496542
0 94248 2981496542
1 71333 42228574
0 7...

output:

1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61
1 62...

result:

ok 49999 lines

Test #7:

score: 0
Accepted
time: 5194ms
memory: 933116kb

input:

100000 100000
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1 30030 4294967295
1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
99800 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2...

result:

ok 162 lines