QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317877 | #4894. 学姐买瓜 | ushg8877 | 0 | 0ms | 0kb | C++14 | 1.3kb | 2024-01-29 21:04:19 | 2024-01-29 21:04:20 |
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(n);
while(ri[tot]!=n){
le[tot+1]=ri[tot]+1;
ri[tot+1]=min(n,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
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
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
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%