QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208547#4270. Double Attendancelmeowdn0 3ms16000kbC++142.8kb2023-10-09 18:44:182023-10-09 18:44:18

Judging History

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

  • [2023-10-09 18:44:18]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:16000kb
  • [2023-10-09 18:44:18]
  • 提交

answer

//vanitas vanitatum et omnia
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128; 
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}      
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;  
typedef vector<pii> vp; 
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=1e6+5,inf=0x3f3f3f3f;
int l[2][N],r[2][N],n[2],K,f[N][2][2],ans;
pii p[2][N];

signed main() {
  n[0]=read(), n[1]=read(), K=read();
  rep(i,1,n[0]) l[0][i]=read(), r[0][i]=read();
  rep(i,1,n[1]) l[1][i]=read(), r[1][i]=read();
  rep(t,0,1) {
    rep(i,1,n[t]) p[t][i]=pii(l[t][i],r[t][i]);
    sort(p[t]+1,p[t]+n[t]+1);
    rep(i,1,n[t]) l[t][i]=p[t][i].fi, r[t][i]=p[t][i].se;
  }
  rep(i,0,n[0]+n[1]) rep(j,0,1) rep(k,0,1) f[i][j][k]=inf;
  f[0][0][0]=0;
  if(l[0][1]==0) f[1][0][0]=0;
  rep(i,0,n[0]+n[1]) {
    rep(j,0,1) rep(k,0,1) {
      int ff=f[i][j][k];
      int x=upper_bound(l[j]+1,l[j]+n[j]+1,ff)-l[j]-1;
      if(x<=n[j]) chmin(f[i][j^1][ff+K<r[j][x]],ff+K);
    }
    rep(j,0,1) rep(k,0,1) {
      if(f[i][j][k]!=inf) ans=i;
      //if(f[i][j][k]!=inf) cout<<i<<" "<<j<<" "<<k<<" "<<f[i][j][k]<<endl;
    }
    if(ans!=i) break;
    rep(j,0,1) {
      int ff=f[i][j][0], k=j^1, x, y, z, res;
      x=upper_bound(l[j]+1,l[j]+n[j]+1,ff)-l[j]-1;
      if(x!=n[j]) chmin(f[i+1][j][0],l[j][x+1]);
      y=upper_bound(l[k]+1,l[k]+n[k]+1,ff+K)-l[k]-1;
      if(ff+K<=r[k][y]) chmin(f[i+1][k][ff+K<r[j][x]],ff+K);
      ff=f[i][j][1];
      x=upper_bound(l[j]+1,l[j]+n[j]+1,ff)-l[j]-1;
      y=upper_bound(l[k]+1,l[k]+n[k]+1,ff)-l[k]-1;
      z=upper_bound(l[k]+1,l[k]+n[k]+1,ff+K)-l[k]-1;
      if(x!=n[j]) chmin(f[i+1][j][l[j][x+1]<r[k][y]],l[j][x+1]);
      if(y<n[k]&&y!=z&&ff+K<=r[k][z]) chmin(f[i+1][k][0],ff+K);
    }
  }
  printf("%d\n",ans);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 15900kb

input:

3 1 8
10 20
100 101
20 21
15 25

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 3ms
memory: 15864kb

input:

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

output:

4

result:

ok single line: '4'

Test #3:

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

input:

10 10 5
4 9
43 48
69 70
70 72
52 67
75 83
100 103
103 1501
10 27
28 40
5 7
27 29
30 39
40 42
42 45
67 80
0 5
45 59
10 20
22 23

output:

18

result:

ok single line: '18'

Test #4:

score: -5
Wrong Answer
time: 3ms
memory: 15892kb

input:

1 1 1
0 1
0 1

output:

2

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #104:

score: 0
Wrong Answer
time: 3ms
memory: 15904kb

input:

1 1 1
0 1
0 1

output:

2

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%