QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#42260#169. Donut DecorationzshcccRE 2ms6720kbC++173.0kb2022-08-01 19:03:292022-08-01 19:03:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-01 19:03:32]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:6720kb
  • [2022-08-01 19:03:29]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define SZ(a) (int)(a.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define pii pair<int,int>
#define mp make_pair
#define  It set<node>::iterator
using namespace std;
#define ll int
int read(){
    char c;
    int t=1,res=0;
    c=getchar();
    while(!isdigit(c)){
        t=t*(-1);c=getchar();
    }
    while(isdigit(c)){
        res=(res<<3)+(res<<1)+c-'0';
        c=getchar();
    }
    return res*t;
}

void write(int n){
    
}
struct node{
    int l,r;
    int v;
    int cnt=1;
    node(int L=0,int R=0,ll V=0,ll Cnt=0):l(L),r(R),v(V),cnt(Cnt){}
    bool operator<( const node &oth)const{
        return l<oth.l;
    }
};
bool cmp( node&x, node&y){
    return x.v<y.v;
}

set<node>s;
set<node>::iterator split(int p){
    auto it=s.lower_bound(node{p,0,0,0});
  
    if(it!=s.end()&&(*it).l==p)return it;
    it--;
    if((*it).r<p)return s.end();
    int l=(*it).l;
    int r=(*it).r;
    ll cnt=(*it).cnt;
    ll v=(*it).v;  
    // cout<<(*it).l<<"   *it  "<<(*it).r<<"   ???"<<endl;
    s.erase(it);
    // cout<<"deb  "<<l<<"  "<<p-1<<"   "<<p<<"   "<<r<<endl;
    s.insert((node){l,p-1,v,p-l});
    return s.insert((node){p,r,v,r-p+1}).first;
}
const int N=2e5+10;
int idx=0;
node buf[N];
inline void assign(int l,int r,int w){
    It itr=split(r+1),itl=split(l);
    int cnt=0;
    // cout<<" ahwy  "<<(*itr).l<<"   "<<(*itl).r<<endl;
    int pl=-1,pr=-1;

    for(auto i=itl;i->r<itr->l;i++){
        // cout<<"????"<<endl;
        if((*i).v+1!=w){
            // cout<<pl<<"   pl"<<endl;
            if(pl!=-1){
            // s.insert(node(pl,pr,w,cnt));
                buf[idx++]=node(pl,pr,w,cnt);
                cnt=0;
                pl=-1;
            }
        }
        else{

            auto tt=(*i);
            if(pl==-1)pl=tt.l;
            pr=tt.r;
            // cout<<tt.l<<"  "<<tt.r<<"   "<<tt.cnt<<endl;
            // cout<<((*i).cnt)<<<<"   !!!cnt"<<endl;
            cnt+=(*i).cnt;
        }
        // if(i==itr)break;
    }
    if(pl!=-1){
        buf[idx++]=node(pl,pr,w,cnt);cnt=0,pl=-1;
    }
    s.erase(itl,itr);
    for(int i=0;i<idx;i++){
        // cout<<idx<<" ??"<<endl;
        s.insert(buf[i]);
    }
    idx=0;
    // cout<<l<<"   "<<r<<"   "<<w<<"   "<<cnt<<endl;
    // s.insert((node){l,r,w,cnt});
}
int n,k;
// int pre[N];

signed main(){
    // cin>>n>>k;
    n=read(),k=read();
    

    int t;
    // s.insert({1,n,0,n});
    rep(i,1,n+1){
        s.insert(node(i,i,0,1));
    }
    // cin>>t;
    t=read();
    rep(i,1,t+1){
        int l,r,k;
        // cin>>l>>r>>k;
        l=read(),r=read(),k=read();
        assign(l,r,k);
    }
    ll res=0;
    for(auto t:s){
        // cout<<t.l<<"  "<<t.r<<"  "<<t.v<<"  "<<t.cnt<<endl;
        if(t.v==k){
            res+=t.cnt;
        }
    }
    cout<<res<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6720kb

input:

3 2
3
1 2 1
2 3 2
3 3 1

output:

1

result:

ok single line: '1'

Test #2:

score: -100
Runtime Error

input:

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

output:


result: