QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#26610#2559. Endless RoadMr_EightWA 4ms39796kbC++146.6kb2022-04-07 20:03:582022-04-29 04:05:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 04:05:38]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:39796kb
  • [2022-04-07 20:03:58]
  • 提交

answer

//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <random>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/priority_queue.hpp>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
#define vi vector<int>
#define ull unsigned long long
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x3f,sizeof(x))
using namespace std;
//using namespace __gnu_pbds;
const double Pi=acos(-1);
namespace fastIO {
	template<class T>
	inline void read(T &x) {
		x=0;
		bool fu=0;
		char ch=0;
		while(ch>'9'||ch<'0') {
			ch=getchar();
			if(ch=='-')fu=1;
		}
		while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
		if(fu)x=-x;
	}
	inline int read() {
		int x=0;
		bool fu=0;
		char ch=0;
		while(ch>'9'||ch<'0') {
			ch=getchar();
			if(ch=='-')fu=1;
		}
		while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
		return fu?-x:x;
	}
	template<class T,class... Args>
	inline void read(T& t,Args&... args) {
		read(t);
		read(args...);
	}
	char _n_u_m_[40];
	template<class T>
	inline void write(T x) {
		if(x==0){
			putchar('0');
			return;
		}
		T tmp = x > 0 ? x : -x ;
		if( x < 0 ) putchar('-') ;
		register int cnt = 0 ;
		while( tmp > 0 ) {
			_n_u_m_[ cnt ++ ] = tmp % 10 + '0' ;
			tmp /= 10 ;
		}
		while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ;
	}
	template<class T>
	inline void write(T x ,char ch) {
		write(x);
		putchar(ch);
	}
}
using namespace fastIO;
namespace G{
	int l[500002],r[500002],tl[500002],tr[500002];
}
using namespace G;
int n;
int p[500002],m,qwq[500002];
pii temp[500002];
#define mid ((l+r)>>1)
namespace B{
	int c[500002];
	inline void add(int pos,int v){
		while(pos<=m){
			c[pos]+=v;
			pos+=(-pos&pos);
		}
	}
	inline int query(int pos){
		int rt=0;
		while(pos){
			rt+=c[pos];
			pos-=(-pos&pos);
		}
		return rt;
	}
};
inline void update(int pos);
namespace S{
	pii mmin[2000002];
	inline void build(int pos,int l,int r){
		if(l==r)mmin[pos]=temp[l];
		else{
			build(pos<<1,l,mid);build(pos<<1|1,mid+1,r);
			mmin[pos]=min(mmin[pos<<1],mmin[pos<<1|1]);
		}
	}
	inline void del(int pos,int l,int r,int q){
		if(l==r)mmin[pos]=make_pair(1000000000,1000000000);
		else{
			if(q<=mid)del(pos<<1,l,mid,q);
			else del(pos<<1|1,mid+1,r,q);
			mmin[pos]=min(mmin[pos<<1],mmin[pos<<1|1]);
		}
	}
	inline pii query(int pos,int l,int r,int ql,int qr){
		if(ql<=l&&qr>=r)return mmin[pos];
		if(ql<=mid&&qr>mid)return min(query(pos<<1,l,mid,ql,qr),query(pos<<1|1,mid+1,r,ql,qr));
		if(ql<=mid)return query(pos<<1,l,mid,ql,qr);
		return query(pos<<1|1,mid+1,r,ql,qr);
	}
	inline void solve(int ql,int qr){
		if(ql>qr)return;
		pii x=query(1,1,m,ql,qr);
		if(x.first<=qr){
			int pos=x.second;
			del(1,1,m,l[pos]);
			update(pos);
			solve(l[pos]+1,qr);
		}
	}
}
namespace M{
	set<int>x,y;
	inline pii query(int pos){//cerr<<endl<<"M "<<pos<<" ";
		auto a=x.upper_bound(pos),b=y.upper_bound(pos);
		return make_pair(b==x.end()?m+1:tr[*b],a==x.begin()?0:*--a);
	}
	inline void ins(int pos){
		x.insert(l[pos]);
		y.insert(r[pos]);
	}
	inline void del(int pos){
		x.erase(l[pos]);
		y.erase(r[pos]);
	}
}
namespace R{
	inline void solve(int l,int r);
}
namespace Q{
	int tag[2000002];
	pii mmin[2000002];
	inline void pushdown(int pos){
		if(tag[pos]){
			tag[pos<<1]+=tag[pos];
			tag[pos<<1|1]+=tag[pos];
			mmin[pos<<1].first+=tag[pos];
			mmin[pos<<1|1].first+=tag[pos];
			tag[pos]=0;
		}
	}
	inline void pushup(int pos){
		mmin[pos]=min(mmin[pos<<1],mmin[pos<<1|1]);
	}
	inline void build(int pos,int l,int r){
		if(l==r)mmin[pos]=make_pair(2100000000,2100000000);
		else{
			build(pos<<1,l,mid);build(pos<<1|1,mid+1,r);pushup(pos);
		}
	}
	inline void add(int pos,int l,int r,int ql,int qr,int v){
		if(ql<=l&&qr>=r)tag[pos]+=v,mmin[pos].first+=v;
		else{
			pushdown(pos);
			if(ql<=mid)add(pos<<1,l,mid,ql,qr,v);
			if(qr>mid)add(pos<<1|1,mid+1,r,ql,qr,v);
			pushup(pos);
		}
	}
	inline void add(int l,int r,int v){
		if(l<=r)add(1,1,m,l,r,v);
	}
	inline void del(int pos,int l,int r,int q){
		if(l==r){
			mmin[pos]=make_pair(2100000000,2100000000);
		}else{
			pushdown(pos);
			if(q<=mid)del(pos<<1,l,mid,q);
			else del(pos<<1|1,mid+1,r,q);
			pushup(pos);
		}
	}
	inline void ins(int pos,int l,int r,int q,int v){
		if(l==r){
			mmin[pos]=make_pair(B::query(G::r[v]-1)-B::query(G::l[v]-1),v);
		}else{
			pushdown(pos);
			if(q<=mid)ins(pos<<1,l,mid,q,v);
			else ins(pos<<1|1,mid+1,r,q,v);
			pushup(pos);
		}
	}
	int now;
	inline void solve(){
		int pos=mmin[1].second;
#ifdef LOCAL
		printf("getans                          ");write(pos,'\n');
#else
		write(pos,' ');
#endif
		if((++now)==n)return;
		del(1,1,m,l[pos]);
		R::solve(l[pos],r[pos]);
		M::del(pos);
		S::del(1,1,m,l[pos]);
		auto pre=M::x.lower_bound(l[pos]),suf=M::y.upper_bound(r[pos]);
		S::solve((pre==M::x.begin()?0:*pre)+1,(suf==M::y.end()?m+1:*suf)-1);
	}
}
namespace R{
	set<int>res;
	inline void solve(int l,int r){
		for(auto i=res.lower_bound(l),iend=res.lower_bound(r);i!=iend;++i){
			B::add(*i,p[*i]-p[*i+1]);//cerr<<"solved "<<*i<<" "<<*i+1<<" "<<p[*i]<<" "<<p[*i+1]<<" ";
			pii v=M::query(*i);//cerr<<v.first<<" "<<v.second<<endl;
			Q::add(v.first,v.second,p[*i]-p[*i+1]);
		}
	}
}
inline void update(int pos){//cerr<<"update "<<pos<<endl;
	Q::ins(1,1,m,l[pos],pos);
	M::ins(pos);
}
int main() {
	cin>>n;
	F(i,1,n)read(l[i],r[i]),p[++m]=l[i],p[++m]=r[i];
	sort(p+1,p+m+1);
	p[m+1]=1000000000;//F(i,1,m)cerr<<p[i]<<" ";cerr<<endl;
	F(i,1,m)qwq[i]=i;
	F(i,1,n)r[i]=(qwq[lower_bound(p+1,p+m+1,r[i])-p]++);
	F(i,1,n)l[i]=(qwq[lower_bound(p+1,p+m+1,l[i])-p]++);
	F(i,1,n)tl[l[i]]=i,tr[r[i]]=l[i];
	F(i,1,m)B::add(i,p[i+1]-p[i]),R::res.insert(i);
	memset(temp,0x3f,sizeof(temp));
	memset(Q::mmin,0x7f,sizeof(Q::mmin));
	F(i,1,n)temp[l[i]]=make_pair(r[i],i);//,cerr<<"    "<<l[i]<<" "<<r[i]<<endl;
	S::build(1,1,m);
	F(i,1,n){
		auto pos=M::x.lower_bound(l[i]);//cerr<<tl[*pos]<<endl;
		if(pos==M::x.end()||r[tl[*pos]]>r[i]){
			update(i);
		}
	}
	F(i,1,n)Q::solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
1 2
2 3
3 4
4 5
1 3
3 5

output:

1 2 5 3 4 6 

result:

ok 6 tokens

Test #2:

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

input:

4
3 7
10 14
1 6
6 11

output:

1 3 2 4 

result:

ok 4 tokens

Test #3:

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

input:

100
50 51
49 51
49 52
48 52
48 53
47 53
47 54
46 54
46 55
45 55
45 56
44 56
44 57
43 57
43 58
42 58
42 59
41 59
41 60
40 60
40 61
39 61
39 62
38 62
38 63
37 63
37 64
36 64
36 65
35 65
35 66
34 66
34 67
33 67
33 68
32 68
32 69
31 69
31 70
30 70
30 71
29 71
29 72
28 72
28 73
27 73
27 74
26 74
26 75
25...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

result:

ok 100 tokens

Test #4:

score: -100
Wrong Answer
time: 4ms
memory: 39796kb

input:

100
41 42
99 100
47 48
50 51
56 57
61 62
27 28
85 86
44 45
3 4
26 27
20 21
92 93
33 34
86 87
69 70
84 85
62 63
81 82
2 3
13 14
32 33
82 83
70 71
46 47
45 46
19 20
83 84
57 59
63 65
59 61
82 84
45 47
48 50
70 72
42 44
84 86
26 28
61 63
2 4
17 19
65 67
54 56
67 69
96 99
42 45
47 50
34 37
14 17
51 54
7...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 21 22 23 24 25 26 27 28 35 29 30 31 34 36 41 42 43 44 45 63 83 55 32 33 71 47 37 38 39 46 52 53 54 57 73 58 77 89 51 66 48 49 50 60 79 62 65 95 91 92 90 69 96 82 72 61 74 80 64 85 78 76 84 98 93 68 86 67 100 99 59 81 75 70 56 87 97 94 88 

result:

wrong answer 12th words differ - expected: '38', found: '12'