QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188374#2716. Interval Collectionlmeowdn0 1170ms216408kbC++144.1kb2023-09-25 19:30:122023-09-25 19:30:12

Judging History

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

  • [2023-09-25 19:30:12]
  • 评测
  • 测评结果:0
  • 用时:1170ms
  • 内存:216408kb
  • [2023-09-25 19:30:12]
  • 提交

answer

#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,m=1e6,inf=1e8;
int ls[N<<1],rs[N<<1],tot=1,ml[N<<1],mr[N<<1],n;
multiset<int> sl[N],sr[N];
map<pii,int> cnt;
struct node {pii a,b; int val;};
bool operator < (const node &a,const node &b) {
  return a.val>b.val;
}
priority_queue<node> q;

void build(int p,int l,int r) {
  ml[p]=-inf, mr[p]=inf; if(l==r) return; int mid=l+r>>1;
  build(ls[p]=++tot,l,mid), build(rs[p]=++tot,mid+1,r);
}
void mdfl(int p,int l,int r,int x,int y) {
  if(l==r) {
    if(!sl[l].size()) ml[p]=-inf;
    else ml[p]=*(--sl[l].end());
    return;
  } int mid=l+r>>1;
  if(x<=mid) mdfl(ls[p],l,mid,x,y);
  else mdfl(rs[p],mid+1,r,x,y);
  ml[p]=max(ml[ls[p]],ml[rs[p]]);
}
void mdfr(int p,int l,int r,int x,int y) {
  if(l==r) {
    if(!sr[l].size()) mr[p]=inf;
    else mr[p]=*sr[l].begin();
    return;
  } int mid=l+r>>1;
  if(y<=mid) mdfr(ls[p],l,mid,x,y);
  else mdfr(rs[p],mid+1,r,x,y);
  mr[p]=min(mr[ls[p]],mr[rs[p]]);
}
int qryl(int p,int l,int r,int x,int y) {
  if(x>y) return -inf;
  if(l==x&&r==y) return ml[p]; int mid=l+r>>1;
  if(y<=mid) return qryl(ls[p],l,mid,x,y);
  else if(x>mid) return qryl(rs[p],mid+1,r,x,y);
  else return max(qryl(ls[p],l,mid,x,mid),qryl(rs[p],mid+1,r,mid+1,y));
}
int qryr(int p,int l,int r,int x,int y) {
  if(x>y) return inf;
  if(l==x&&r==y) return mr[p]; int mid=l+r>>1;
  if(y<=mid) return qryr(ls[p],l,mid,x,y);
  else if(x>mid) return qryr(rs[p],mid+1,r,x,y);
  else return min(qryr(ls[p],l,mid,x,mid),qryr(rs[p],mid+1,r,mid+1,y));
}
void addl(int l,int r) {
  if(l<=0||r>m) return;
  int pl=qryl(1,1,m,1,l);
  if(pl!=-inf) {
    int pr=*sr[pl].begin();
    q.push((node){pii(pl,pr),pii(l,r),r-pl});
  }
}
void addr(int l,int r) {
  if(l<=0||r>m) return;
  int qr=qryr(1,1,m,r,m);
  if(qr!=inf) {
    int ql=*(--sl[qr].end());
    q.push((node){pii(l,r),pii(ql,qr),qr-l});
  }
}

signed main() {
  n=read(); build(1,1,m);
  rep(i,1,n) {
    static char s[3]; int l,r;
    scanf("%s%d%d",s,&l,&r);
    if(s[0]=='A') {
      sl[r].insert(l), sr[l].insert(r);
      cnt[pii(l,r)]++;
      addl(l,r), addr(l,r);
      mdfl(1,1,m,r,l);
      mdfr(1,1,m,r,l);
    } else {
      sl[r].erase(sl[r].find(l));
      sr[l].erase(sr[l].find(r));
      cnt[pii(l,r)]--;
      mdfl(1,1,m,r,l);
      mdfr(1,1,m,r,l);
      int pl=qryl(1,1,m,1,r);
      if(pl!=-inf) {
        int pr=*sr[pl].begin();
        addr(pl,pr);
      }
      int qr=qryr(1,1,m,l,m);
      if(qr!=-inf) {
        int ql=*(--sl[qr].end());
        addl(ql,qr);
      }
    }
    while(!q.empty()) {
      auto [a,b,v]=q.top();
      if(cnt[a]&&cnt[b]) {
        printf("%d\n",v);
        break;
      } q.pop();
    }
    if(q.empty()) {
      int l=qryl(1,1,m,1,m), r=qryr(1,1,m,1,m);
      int al=*(--sl[r].end()), ar=*sr[l].begin();
      printf("%d\n",ar-al);
    }
  }
  return 0;
}

詳細信息

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

500
A 85614 618681
A 96881 534557
A 371656 884110
A 55265 991070
A 135033 917439
A 467668 648254
A 810282 995373
A 578086 947503
A 63927 975158
A 142141 348881
A 372691 541176
A 409911 918917
A 594071 750141
A 26557 936338
A 194871 545990
A 584676 799137
A 153204 901288
A 22939 601013
A 102411 75491...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #61:

score: 8
Accepted
time: 16ms
memory: 128880kb

input:

6
A 1 4
A 3 6
A 7 9
A 8 13
A 10 11
A 12 20

output:

3
5
6
6
4
4

result:

ok 6 lines

Test #62:

score: 0
Accepted
time: 15ms
memory: 128752kb

input:

3
A 1 9
A 6 15
A 5 10

output:

8
14
14

result:

ok 3 lines

Test #63:

score: 0
Accepted
time: 24ms
memory: 128796kb

input:

1
A 1 1000000

output:

999999

result:

ok single line: '999999'

Test #64:

score: 0
Accepted
time: 40ms
memory: 129924kb

input:

12000
A 174045 346671
A 58746 969907
A 52277 860980
A 51687 822337
A 320881 593470
A 22653 724673
A 347122 956041
A 514874 780251
A 155146 643918
A 116754 682718
A 374599 823274
A 373533 892185
A 63743 897550
A 224312 990829
A 423470 808028
A 212113 622665
A 263437 824930
A 416679 820773
A 515191 97...

output:

172626
172626
172626
172626
419425
419425
781996
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206
606206...

result:

ok 12000 lines

Test #65:

score: -8
Runtime Error

input:

12000
A 375053 948875
A 28782 831017
A 52211 937756
A 80144 303540
A 57568 955525
A 117481 966016
A 92106 774943
A 456401 788566
A 48304 887683
A 120272 532671
A 335039 490427
A 131773 461751
A 175340 859808
A 742792 956002
A 195683 690807
A 444964 948448
A 196618 213884
A 352567 814097
A 85197 7149...

output:

573822
920093
920093
868731
868731
868731
868731
708422
708422
708422
410283
410283
410283
410283
410283
410283
293809
293809
293809
293809
293809
293809
293809
293809
293809
293809
293809
293809
293809
293809
293809
293809
187217
187217
187217
187217
187217
187217
157635
157635
157635
157635
157635...

result:


Subtask #3:

score: 0
Runtime Error

Test #133:

score: 0
Runtime Error

input:

50000
A 407618 981209
A 14832 978274
A 21496 974294
A 159141 441444
A 103094 770273
A 133173 804558
A 243940 901651
A 590784 872146
A 158069 795070
A 114024 817376
A 7306 972394
A 156995 964178
A 126045 964369
A 23896 862655
A 405378 416054
A 634234 672082
A 369490 983098
A 83772 519426
A 699410 854...

output:

573591
966377
959713
822068
822068
822068
822068
713005
713005
713005
713005
713005
713005
713005
466768
266704
266704
266704
220208
220208
220208
220208
220208
220208
220208
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952
122952...

result:


Subtask #4:

score: 0
Runtime Error

Test #193:

score: 4
Accepted
time: 209ms
memory: 163408kb

input:

200000
A 1 7
A 8 14
A 15 21
A 22 28
A 29 35
A 36 42
A 43 49
A 50 56
A 57 63
A 64 70
A 71 77
A 78 84
A 85 91
A 92 98
A 99 105
A 106 112
A 113 119
A 120 126
A 127 133
A 134 140
A 141 147
A 148 154
A 155 161
A 162 168
A 169 175
A 176 182
A 183 189
A 190 196
A 197 203
A 204 210
A 211 217
A 218 224
A 225...

output:

6
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
13
1...

result:

ok 200000 lines

Test #194:

score: 0
Accepted
time: 194ms
memory: 163540kb

input:

200000
A 900009 900010
A 900007 900008
A 900005 900006
A 900003 900004
A 900001 900002
A 899999 900000
A 899997 899998
A 899995 899996
A 899993 899994
A 899991 899992
A 899989 899990
A 899987 899988
A 899985 899986
A 899983 899984
A 899981 899982
A 899979 899980
A 899977 899978
A 899975 899976
A 899...

output:

1
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
...

result:

ok 200000 lines

Test #195:

score: 0
Accepted
time: 367ms
memory: 198612kb

input:

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

output:

1
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
...

result:

ok 400000 lines

Test #196:

score: 0
Accepted
time: 372ms
memory: 198696kb

input:

400000
A 799999 800000
A 799997 799998
A 799995 799996
A 799993 799994
A 799991 799992
A 799989 799990
A 799987 799988
A 799985 799986
A 799983 799984
A 799981 799982
A 799979 799980
A 799977 799978
A 799975 799976
A 799973 799974
A 799971 799972
A 799969 799970
A 799967 799968
A 799965 799966
A 799...

output:

1
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
...

result:

ok 400000 lines

Test #197:

score: 0
Accepted
time: 480ms
memory: 216408kb

input:

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

output:

1
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
...

result:

ok 499999 lines

Test #198:

score: 0
Accepted
time: 486ms
memory: 216380kb

input:

499999
A 999997 999998
A 999995 999996
A 999993 999994
A 999991 999992
A 999989 999990
A 999987 999988
A 999985 999986
A 999983 999984
A 999981 999982
A 999979 999980
A 999977 999978
A 999975 999976
A 999973 999974
A 999971 999972
A 999969 999970
A 999967 999968
A 999965 999966
A 999963 999964
A 999...

output:

1
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
...

result:

ok 499999 lines

Test #199:

score: -4
Runtime Error

input:

500000
A 50 911
A 990 1785
A 1860 2691
A 7 29
A 34 44
A 45 46
A 2865 3234
A 1803 1842
A 47 48
A 1846 1856
A 1787 1802
A 1857 1859
A 931 982
A 1844 1845
A 2719 2824
A 30 33
A 2 4
A 2849 2855
A 2862 2864
A 5 6
A 920 925
A 983 988
A 2693 2718
A 927 930
A 915 916
A 918 919
A 912 914
A 2856 2859
A 2828 2...

output:

861
1735
1701
904
37
12
12
12
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
...

result:


Subtask #5:

score: 0
Runtime Error

Test #213:

score: 3
Accepted
time: 1170ms
memory: 194516kb

input:

500000
A 177873 500336
A 457824 814681
A 841342 988692
A 419772 679383
A 932 397613
A 112565 840517
A 21558 993484
A 388360 943423
A 51953 706434
A 444776 874634
A 672973 719874
A 324528 972601
A 711851 858636
A 219651 966235
A 89897 472254
A 40578 919362
A 340868 944392
A 163582 585658
A 637082 954...

output:

322463
636808
530868
530868
530868
530868
530868
530868
530868
530868
315719
315719
315719
315719
315719
315719
315719
315719
315719
315719
315719
315719
315719
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305
131305...

result:

ok 500000 lines

Test #214:

score: -3
Runtime Error

input:

500000
A 19984 450284
A 96761 997086
A 316867 923102
A 593966 846630
A 324820 370426
A 737058 767339
A 609035 732288
A 27614 753125
A 47817 778799
A 511932 911251
A 325127 545889
A 194006 849501
A 397366 989935
A 384642 644398
A 151785 160335
A 435217 791912
A 75861 637008
A 109997 799477
A 7242 712...

output:

430300
977102
903118
826646
521810
442519
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304
158304...

result: