QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317880 | #4894. 学姐买瓜 | ushg8877 | 0 | 1ms | 5936kb | C++14 | 1.3kb | 2024-01-29 21:05:50 | 2024-01-29 21:05:50 |
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3e5+5;
const int sqN=605;
int n,m,le[sqN],ri[sqN],tot,bel[MAXN],to[MAXN],val[MAXN];
int a[MAXN];
void rebuild(int id){
for(int i=ri[id];i>=le[id];i--){
if(!a[i]){
if(i==ri[id]){
to[i]=i+1;val[i]=0;
}else to[i]=to[i+1],val[i]=val[i+1];
}else{
if(a[i]<ri[id]){
to[i]=to[a[i]+1];
val[i]=val[a[i]+1]+1;
}else{
to[i]=a[i]+1;
val[i]=1;
}
}
}
}
void build(){
int sq=sqrt(m);
while(ri[tot]!=m){
le[tot+1]=ri[tot]+1;
ri[tot+1]=min(m,le[tot+1]+sq);
++tot;
}
for(int i=1;i<=tot;i++) for(int j=le[i];j<=ri[i];j++) bel[j]=i;
for(int i=1;i<=tot;i++) rebuild(i);
}
int query(int l,int r){
int ans=0,x=l;
while(to[x]<=r) ans+=val[x],x=to[x];
while(x<=r){
ans+=(a[x]>0&&a[x]<=r);
x=(a[x]?a[x]+1:x+1);
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
// freopen("c.in","r",stdin);
cin>>n>>m;
build();
set<int> se;
for(int i=1;i<=n;i++){
int o,l,r;cin>>o>>l>>r;
if(o==1){
if(!a[l]||a[l]>r){
a[l]=r;
rebuild(bel[l]);
se.insert(l);
while(se.lower_bound(l)!=se.begin()){
auto it=--se.lower_bound(l);
if(a[*it]>=a[l]){
a[*it]=0;rebuild(bel[*it]);
se.erase(it);
}else break;
}
}
}else{
cout<<query(l,r)<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 1ms
memory: 5936kb
input:
11 13 2 4 4 1 11 12 1 1 5 1 2 3 1 2 10 2 2 8 1 6 6 2 2 10 1 6 11 2 2 3 2 2 13
output:
0 1 2 1 3
result:
ok 5 lines
Test #2:
score: -20
Wrong Answer
time: 0ms
memory: 5664kb
input:
2000 2000 2 66 273 1 475 1570 2 51 958 2 731 1771 1 1286 1627 1 37 892 1 529 890 2 155 1486 1 87 1815 1 576 1872 2 1269 1515 2 1521 1794 2 634 1887 2 204 1668 1 351 1679 2 1571 1599 1 243 681 2 1 2000 2 1 2000 2 564 648 2 1215 1807 2 466 1617 1 1119 1348 1 497 886 2 1358 1487 2 173 1974 1 401 1294 2...
output:
0 0 0 1 0 0 1 2 0 2 2 0 1 1 0 2 1 1 0 1 0 1 0 0 1 2 1 1 0 2 1 1 0 0 1 2 0 1 1 0 1 1 0 0 1 0 0 0 1 2 1 0 3 0 2 0 2 0 1 0 0 1 3 0 0 2 3 0 0 1 0 2 0 6 0 6 1 0 0 7 1 0 8 2 2 0 3 0 2 5 3 0 5 0 3 4 5 0 0 2 0 2 5 1 0 1 0 6 9 0 1 0 0 0 1 1 1 2 2 0 4 0 5 0 2 2 4 5 1 5 3 2 4 5 1 5 4 2 2 6 0 5 5 4 4 0 2 0 1 1 ...
result:
wrong answer 29th lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%