QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#723142#6765. Don't Really Like How The Story EndsSound_MediumWA 252ms19000kbC++233.0kb2024-11-07 21:15:472024-11-07 21:15:47

Judging History

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

  • [2024-11-07 21:15:47]
  • 评测
  • 测评结果:WA
  • 用时:252ms
  • 内存:19000kb
  • [2024-11-07 21:15:47]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
const int M=1e6+10;
int logg[M];
    vector<int>id(M,-1);
void log22(int n){
    for(int i=2;i<=n;i++){
        logg[i]=logg[i/2]+1;
    }
}
void solve () {

    cin>>n>>m;
    vector<vector<int>>g(n+1);
    vector<vector<int>>e(n+1);
    map<pair<int,int>,int>mp;
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        if(u==v)continue;
        if(mp[{u,v}]||mp[{v,u}])continue;
        mp[{u,v}]=mp[{v,u}]=1;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int>ip(n+1,-1);
    vector<pair<int,int>>a;
    a.push_back({0,0});
    for(int i=1;i<=n;i++){
        sort(g[i].begin(),g[i].end());
        // if(g[i].size()){
        //     a.push_back({g[i].back(),i});
        //     ip[i]=a.size()-1;
        // }
        for(auto v:g[i]){
            e[v].push_back(i);
            a.push_back({g[i].back(),i});
            id[(int)a.size()-1]=i;
        }
        if(g[i].size())
            ip[i]=a.size()-1;
    }
    for(int i=1;i<=n;i++){
        sort(e[i].begin(),e[i].end());
    }
    int cnt=0;
    const int N=a.size()+10;
    vector<vector<int>>fa(N,vector<int>(30,0));
    for(int i=1;i<N;i++)fa[i][0]=a[i].first;
    for(int i=1;i<=22;i++){
        for(int j=1;j+(1<<i)-1<=n;j++){
            fa[j][i]=max(fa[j][i-1],fa[j+(1<<(i-1))][i-1]);
        }
    }
    auto f=[&](int l,int r)->int{
        {}
        int s=logg[r-l+1];
        return max(fa[l][s],fa[r-(1<<s)+1][s]);
    };
    // int cnt=0;
    // for(auto [x,y]:a)cerr<<x<<" ";
    // for(int i=1;i<=4;i++)cerr<<id[i]<<" ";cerr<<endl;
    int st=0;
    for(int i=2;i<=n;i++){
        st=max(st,ip[i-1]);
        if(mp[{i-1,i}]==1) continue;
        else if(ip[i]==-1||g[i].size()==0){
            ip[i]=st;
            cnt++;
        }else {
            auto check=[&](int x,int r)->bool{
                {}
                return f(x,r)<=i;
            };
            int l=1,r=ip[i-1];
            // cerr<<i<<" "<<l<<" "<<r<<endl;
            if(l>r){
                cnt++;
                continue;
            }
            while(l<r){
                int mid=l+r>>1;
                if(check(mid,r))r=mid;
                else l=mid+1;
            }
            // if(i==4)cerr<<l<<" ";
            int L=id[l],R=id[ip[i-1]];
            if(id[l]==id[l-1]){
                if(L==R){
                    cnt++;
                    continue;
                }
                L++;
            }
            // cerr<<L<<" "<<R<<endl;
            int k=lower_bound(e[i].begin(),e[i].end(),L)-e[i].begin();
            if(e[i][k]<=R);
            else cnt++;
        }

    // cerr<<"8";
    }
    for(int i=0;i<=N;i++)id[i]=-1;
    cout<<cnt<<endl;
}
signed main () {
    int T = 1; 
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>T;
    log22(1e6);
    while (T --) solve ();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 18856kb

input:

3
2 3
1 1
1 2
2 1
4 1
1 4
4 2
1 2
3 4

output:

0
2
1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 252ms
memory: 19000kb

input:

117747
3 7
2 1
3 3
1 3
1 1
3 2
1 1
3 1
4 8
2 3
4 3
3 2
4 2
1 3
2 1
4 3
2 4
3 4
2 3
2 2
3 3
1 1
2 5
1 1
2 2
2 2
1 2
2 2
3 7
2 1
1 2
3 3
3 2
1 2
3 3
3 2
4 5
1 2
3 3
4 4
1 4
2 1
3 1
3 2
1 3
1 1
1 1
1 1
1 6
1 1
1 1
1 1
1 1
1 1
1 1
5 4
2 1
2 5
1 3
3 2
4 7
1 1
2 4
3 2
1 1
1 1
4 2
2 3
5 8
3 3
2 2
4 2
1 4
1...

output:

0
0
1
0
0
1
1
0
0
1
1
1
0
0
2
0
2
0
1
0
0
3
0
0
0
2
1
1
1
0
0
0
2
0
2
1
3
0
2
0
3
1
2
1
0
0
1
2
0
2
0
1
1
0
0
2
0
0
0
1
0
2
0
1
0
0
1
0
0
3
2
0
0
0
1
0
2
3
0
0
1
1
1
0
0
2
1
3
0
1
2
0
0
0
2
0
0
3
1
0
2
0
0
0
1
0
0
0
0
0
0
4
0
0
0
0
0
0
2
0
1
0
0
1
0
0
0
2
0
1
0
0
0
3
0
1
2
0
0
0
0
1
0
0
1
1
1
0
0
0
...

result:

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