QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#341359#1429. HitrageOfThunder#TL 48ms7948kbC++143.9kb2024-02-29 17:57:032024-02-29 17:57:04

Judging History

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

  • [2024-02-29 17:57:04]
  • 评测
  • 测评结果:TL
  • 用时:48ms
  • 内存:7948kb
  • [2024-02-29 17:57:03]
  • 提交

answer

#include<bits/stdc++.h>

#define ll long long
#define mk make_pair
#define fi first
#define se second

using namespace std;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
	for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
	return x*f;
}

template<typename T>void cmax(T &x,T v){x=max(x,v);}
template<typename T>void cmin(T &x,T v){x=min(x,v);}

const int N=3e6+5;
int G[N],st[N],ed[N],n,Gv[N];

const int INF=1.1e9;
int dis[N],cnt[N];
bool inq[N];
bool spfa(int s){
//	cout<<"spfa "<<s<<endl;
	deque<int>q;int cont=0;
	for(int i=1;i<=n;i++)dis[i]=INF,cnt[i]=0,inq[i]=0;
	q.push_front(s),dis[s]=0,inq[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop_front();
		for(int i=st[u];i<=ed[u];i++){
			int v=G[i],w=Gv[i];
			if(dis[v]>dis[u]+w){
				dis[v]=dis[u]+w,cnt[v]=cnt[u]+1;
				if(cnt[v]>=n)return false;
//				if(++cont>=30000000)return false;
				if(inq[v])continue;
				if(q.empty())q.push_back(v);
				else if(dis[v]>=dis[q.front()])q.push_back(v);
				else q.push_front(v);
				int f=q.front();q.pop_front();
				if(q.empty())q.push_back(f);
				int b=q.back();q.pop_back();
				if(dis[f]>dis[b])swap(f,b);
				q.push_front(f),q.push_back(b);
			}
		}
	}
//	cout<<"dis = ";for(int i=1;i<=n;i++)cout<<dis[i]<<" ";puts("");
	return true;
}

int V=0;
struct BIT{
	int c[N];
	void clear(int vv){for(int i=1;i<=vv;i++)c[i]=0;}
	int lowbit(int x){return x&(-x);}
	void add(int x){for(int i=x;i<=V;i+=lowbit(i))c[i]++;}
	int qsum(int x){int res=0;for(int i=x;i;i-=lowbit(i))res+=c[i];return res;}
}T;

vector<int>pos;
int calc(vector<pair<int,int> >Is){
	vector<int>lsh;pos.clear();
	for(auto [l,r]:Is)lsh.emplace_back(l),lsh.emplace_back(r);
	V=lsh.size();
	sort(lsh.begin(),lsh.end()),lsh.resize(unique(lsh.begin(),lsh.end())-lsh.begin());
//	cout<<"V = "<<V<<endl;
	for(auto &[l,r]:Is){
		l=lower_bound(lsh.begin(),lsh.end(),l)-lsh.begin()+1;
		r=lower_bound(lsh.begin(),lsh.end(),r)-lsh.begin()+1;
	}
	sort(Is.begin(),Is.end(),[&](pair<int,int>A,pair<int,int>B){return A.se<B.se;});
	for(auto [l,r]:Is)if(T.qsum(r)==T.qsum(l-1)){
		T.add(r);
		pos.emplace_back(lsh[r-1]);
//		cout<<"l,r = "<<lsh[l-1]<<" "<<lsh[r-1]<<endl;
//		cout<<"add point = "<<r<<endl;
	}
	
	int ans=0;
	for(auto [l,r]:Is)cmax(ans,T.qsum(r)-T.qsum(l-1));
	
	T.clear(V);
	return ans;
}

void solve(){
	n=read();
	vector<pair<int,int> >Is(n);
	vector<int>lsh;
	for(int i=0;i<n;i++)Is[i].fi=read(),Is[i].se=read();
	int t=calc(Is);
//	cout<<"t = "<<t<<endl;
	for(auto &[l,r]:Is)r++;
	for(auto [l,r]:Is)lsh.emplace_back(l),lsh.emplace_back(r);
	sort(lsh.begin(),lsh.end()),lsh.resize(unique(lsh.begin(),lsh.end())-lsh.begin());
	
	for(auto &[l,r]:Is){
		l=lower_bound(lsh.begin(),lsh.end(),l)-lsh.begin()+1;
		r=lower_bound(lsh.begin(),lsh.end(),r)-lsh.begin()+1;
	}
	
	n=lsh.size();
	vector<int>deg(n+1);
	
	auto inse=[&](int u,int v,int w){deg[u]++,deg[v]++;};
	auto adde=[&](int u,int v,int w){st[u]--;G[st[u]]=v,Gv[st[u]]=w;return st[u];};
	
	// (x,y,z) : a[y] <= a[x] + z ---> a[y] - a[x] <= z
	
	for(int i=0;i+1<n;i++)inse(i+1,i+2,lsh[i+1]-lsh[i]),inse(i+2,i+1,0);
	for(auto [l,r]:Is)inse(r,l,-1),inse(l,r,t-1);
	
	for(int i=1;i<=n;i++)deg[i]+=deg[i-1],st[i]=deg[i]+1,ed[i]=deg[i];
	
	for(int i=0;i+1<n;i++)adde(i+1,i+2,lsh[i+1]-lsh[i]),adde(i+2,i+1,0);
	for(auto [l,r]:Is)adde(r,l,-1),adde(l,r,t-1);
	
	if(!spfa(1)){
		cout<<t<<" "<<pos.size()<<" ";for(int x:pos)cout<<x<<" ";puts("");
		return ;
	}
	vector<int>vals;
	for(int i=1;i<=n;i++){
		int cnt=dis[i+1]-dis[i];
		for(int j=lsh[i-1];j<=lsh[i-1]+cnt-1;j++)vals.emplace_back(j);
	}
	
	cout<<t-1<<" "<<vals.size()<<" ";for(int x:vals)cout<<x<<" ";puts("");
}

signed main(void){

#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
#endif

	int tt=read();while(tt--)solve();

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7660kb

input:

4
4
0 1
2 3
4 5
3 5
5
0 70
0 10
20 30
40 50
60 70
8
-1 7
-2 -1
-9 -7
-8 9
-9 -7
-2 4
-7 4
3 9
5
0 1
0 2
2 3
3 5
4 5

output:

1 3 0 2 4 
4 4 10 30 50 70 
2 3 -9 -2 3 
2 3 1 3 5 

result:

ok ok, tt = 4

Test #2:

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

input:

1
1
0 1

output:

1 1 1 

result:

ok ok, tt = 1

Test #3:

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

input:

3
1
-1000000000 1000000000
1
-1000000000 -999999999
1
999999999 1000000000

output:

1 1 1000000000 
1 1 -999999999 
1 1 1000000000 

result:

ok ok, tt = 3

Test #4:

score: 0
Accepted
time: 42ms
memory: 7948kb

input:

100000
1
-755794993 -744839313
1
638832683 645984490
1
333736843 342792055
1
-412526164 -400411740
1
193156287 205856204
1
266085745 268256106
1
789502967 806620391
1
85305828 86560242
1
-655573585 -644094805
1
517734490 518776542
1
-966001098 -958188900
1
-780504491 -762439365
1
-896592598 -8804653...

output:

1 1 -744839313 
1 1 645984490 
1 1 342792055 
1 1 -400411740 
1 1 205856204 
1 1 268256106 
1 1 806620391 
1 1 86560242 
1 1 -644094805 
1 1 518776542 
1 1 -958188900 
1 1 -762439365 
1 1 -880465378 
1 1 -545603970 
1 1 674193870 
1 1 -613177432 
1 1 -189815796 
1 1 -636284766 
1 1 -212256845 
1 1 -...

result:

ok ok, tt = 100000

Test #5:

score: 0
Accepted
time: 47ms
memory: 5676kb

input:

100000
1
-392749917 -319069731
1
761382535 804248178
1
-858764838 -819815600
1
-87503649 -20800126
1
-69252318 64456029
1
-848092983 -666742404
1
-659061625 -620054847
1
-982031817 -883932130
1
-47104919 97672798
1
-494834028 -456770262
1
496748206 692802903
1
572757539 669651153
1
-484466016 -41314...

output:

1 1 -319069731 
1 1 804248178 
1 1 -819815600 
1 1 -20800126 
1 1 64456029 
1 1 -666742404 
1 1 -620054847 
1 1 -883932130 
1 1 97672798 
1 1 -456770262 
1 1 692802903 
1 1 669651153 
1 1 -413146928 
1 1 912121104 
1 1 -402000624 
1 1 310772000 
1 1 -329279769 
1 1 888975125 
1 1 -505832802 
1 1 310...

result:

ok ok, tt = 100000

Test #6:

score: 0
Accepted
time: 42ms
memory: 5680kb

input:

100000
1
-422738609 -95619025
1
496655203 761501973
1
-253341552 895113150
1
-213934938 560617332
1
257193179 510136024
1
-684784337 -650911183
1
-999254900 62633326
1
-627557633 641989470
1
-682383675 66116491
1
-859630523 340664034
1
-422590930 433070710
1
259879968 316877801
1
-90014752 991378355...

output:

1 1 -95619025 
1 1 761501973 
1 1 895113150 
1 1 560617332 
1 1 510136024 
1 1 -650911183 
1 1 62633326 
1 1 641989470 
1 1 66116491 
1 1 340664034 
1 1 433070710 
1 1 316877801 
1 1 991378355 
1 1 351139472 
1 1 643790197 
1 1 899761936 
1 1 -713126923 
1 1 358738130 
1 1 502116510 
1 1 647513652 
...

result:

ok ok, tt = 100000

Test #7:

score: 0
Accepted
time: 48ms
memory: 5612kb

input:

100000
1
-146170891 -135832850
1
-758721094 -739814745
1
434418655 436843128
1
584625787 597671579
1
-54920782 -48746711
1
-890924962 -874340357
1
-955254050 -945006677
1
276114326 279390556
1
-291805472 -288200984
1
673823575 685514644
1
-43237398 -31640268
1
-239622315 -224829882
1
-596965402 -595...

output:

1 1 -135832850 
1 1 -739814745 
1 1 436843128 
1 1 597671579 
1 1 -48746711 
1 1 -874340357 
1 1 -945006677 
1 1 279390556 
1 1 -288200984 
1 1 685514644 
1 1 -31640268 
1 1 -224829882 
1 1 -595948258 
1 1 -886772435 
1 1 281278372 
1 1 -154122163 
1 1 302173751 
1 1 117393731 
1 1 -725867793 
1 1 -...

result:

ok ok, tt = 100000

Test #8:

score: 0
Accepted
time: 47ms
memory: 7704kb

input:

100000
1
-938525664 -817076126
1
-932701889 -823854498
1
-198817321 -90954343
1
852989237 895167117
1
-657597128 -592296022
1
-189337058 -60845257
1
-308394755 -143079067
1
-798793040 -658589397
1
587269730 632505978
1
463959892 651681553
1
210139744 354710208
1
-738322653 -579254528
1
-473167271 -4...

output:

1 1 -817076126 
1 1 -823854498 
1 1 -90954343 
1 1 895167117 
1 1 -592296022 
1 1 -60845257 
1 1 -143079067 
1 1 -658589397 
1 1 632505978 
1 1 651681553 
1 1 354710208 
1 1 -579254528 
1 1 -415805150 
1 1 -620402885 
1 1 -80905695 
1 1 866571582 
1 1 884604855 
1 1 888448333 
1 1 -97223882 
1 1 791...

result:

ok ok, tt = 100000

Test #9:

score: 0
Accepted
time: 42ms
memory: 5700kb

input:

100000
1
-124550996 175843021
1
-993480749 369513273
1
-472345946 866834459
1
51146719 619481540
1
-953985291 -388861986
1
30060232 86153621
1
397966610 670657620
1
228037899 527397835
1
-328812046 777147616
1
528770087 999819348
1
-443642177 430027557
1
-985366041 937429463
1
286165886 375753871
1
...

output:

1 1 175843021 
1 1 369513273 
1 1 866834459 
1 1 619481540 
1 1 -388861986 
1 1 86153621 
1 1 670657620 
1 1 527397835 
1 1 777147616 
1 1 999819348 
1 1 430027557 
1 1 937429463 
1 1 375753871 
1 1 -241036764 
1 1 253849507 
1 1 904700981 
1 1 875953108 
1 1 121979058 
1 1 465863397 
1 1 901461978 ...

result:

ok ok, tt = 100000

Test #10:

score: -100
Time Limit Exceeded

input:

18139
4
-336270587 -330557331
-252002330 -239258910
-186846904 -186440987
848243159 868102416
3
-195461235 -180651308
-250893512 -232183484
741194405 748153230
1
-583374820 -573301094
2
-289487516 -278362438
-617984192 -600701104
3
361103576 377771047
-629713150 -625261223
760487909 765234419
2
-789...

output:


result: