제출 #1093004

#제출 시각아이디문제언어결과실행 시간메모리
10930040pt1mus23Drvca (COCI19_drvca)C++14
0 / 110
225 ms43900 KiB
/*palavra*/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define ins insert
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7,sze = 1e5 +23,inf = INT_MAX, L = 30; 

pair<int,int> dp[L][sze];
int lg[sze];

pair<int,int> qry(int l,int r){
    pair<int,int> res;
    int i = lg[r-l+1];
    res.first = min(dp[i][l].first,dp[i][r - (1<<i) +1].first);
    res.second = max(dp[i][l].second,dp[i][r - (1<<i) +1].second);
    return res;
}
int check(int l,int r,int cc){
    pair<int,int> res=qry(l,r);
    return ( res.first==res.second && res.first==cc) ;
}
void opt1z(){
    int n;
    cin>>n;
    for(int i=2;i<=n;i++){
        lg[i]=lg[i/2] +1;
    }
    vector<int> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(all(arr));
    bool eq=false;
    int qq=0;
    for(int i=0;i+1<n;++i){
        if(arr[i]==arr[i+1]){
            eq=true;break;
            qq=arr[i];
        }
    }
    if(eq){ 
        vector<int> alst,blst;
        for(auto v:arr){
            if(v==qq){
                alst.pb(v);
            }
            else{
                blst.pb(v);
            }
        }
        if(!(alst.empty() || blst.empty())){
            int m = blst.size();
            bool ff=true;
            for(int i=1;i+1<m;i++){
                if( ( blst[i+1]-blst[i]) != (blst[i]-blst[i-1]) ){
                    ff=false;
                }
            }
            if(ff){
                cout<<alst.size()<<"\n";
                for(auto v:alst) cout<<v<<" ";cout<<"\n";
                cout<<blst.size()<<"\n";
                for(auto v:blst) cout<<v<<" ";cout<<"\n";
                return;
            }
        }
        if(blst.empty()){
            alst.pop_back();
            blst.pb(alst.back());
            cout<<alst.size()<<"\n";
            for(auto v:alst) cout<<v<<" ";cout<<"\n";
            cout<<blst.size()<<"\n";
            for(auto v:blst) cout<<v<<" ";cout<<"\n";
            return;
        }
    }

    vector<int> tmp;
    for(int i=0;i<n-1;i++){
        tmp.pb(arr[i]);
    }
    bool fff=true;
    for(int i=1;i+1<tmp.size();i++){
        if((tmp[i+1]-tmp[i]) != (tmp[i]-tmp[i-1])){
            fff=false;
        }
    }
    if(fff){
        cout<<"1 \n"<<arr.back()<<endl;
        cout<<tmp.size()<<"\n";
        for(auto v:tmp) cout<<v<<" "; cout<<endl;
        return;
    }

    vector<int> lst;
    for(int i=0;i+1<n;i++){
        lst.pb(arr[i+1]-arr[i]);
        dp[0][i].first=lst[i];
        dp[0][i].second=lst[i];
    }
    int m = lst.size();

    for(int i =1;i<L;i++){
        for(int j=0;j + (1<<i)<=m;j++){
            dp[i][j].first = min(dp[i-1][j].first, dp[i-1][j + (1<<(i-1))].first); 
            dp[i][j].second = max(dp[i-1][j].second, dp[i-1][j + (1<<(i-1))].second); 
        }
    }
    // for(auto v:arr) cout<<v<<" ";cout<<endl;
    map<int,int> idx;
    vector<int> ranges;
    for(int i=0;i<n;i++){
        idx[arr[i]]=i;
    }
    for(int i=0;i+1<n;i++){
        int ferq = arr.back() - arr[i];
        if(ferq==0){
            break;
        }
        // cout<<ferq<<endl;
        int curr = arr[i];
        bool flag=true;

        ranges.clear(); // optimize later maybe
        ranges.pb(n-1);
        ranges.pb(i);
        while(true){

            int nx = curr - ferq;
            // cout<<ferq<<" ==== "<<nx<<endl;
            if(idx.find(nx)!=idx.end()){
                // cout<<nx<<endl;
                ranges.pb(idx[nx]);
                curr=nx;
            }
            else{
                break;
            }
        }
        // cout<<ferq<<" => \n";
        // for(auto v:ranges) cout<<v<<" ";cout<<"\n";
        int len = ranges.size();
        // vector<int> ferqs;
        int last=-1;
        int ortalar = -1;
        for(int j=1;j<len;j++){
            int r = ranges[j-1]-1;
            int l = ranges[j]+1;
            if(l<=r){
                // cout<<l<<";"<<r<<" "<<ranges[j-1]<<","<<ranges[j]<<endl;
                if(l<r){
                    int lx=l;
                    int rx = r-1;
                    pair<int,int> res = qry(lx,rx);
                    if(res.first!=res.second){
                        // cout<<ferq<<" error"<<endl;
                        flag=false;
                        break;
                    }
                    if(last==-1){
                        ortalar=res.first;
                    }
                    else{
                        if(ortalar==-1){
                            ortalar = last -arr[r];
                            if(ortalar!=res.first){
                                // cout<<ferq<<" error:"<< ortalar<<" "<<last<<" "<<arr[r]<<" "<<res.first<<endl;
                                flag=false;
                                break;
                            }
                        }
                        else{
                            if(( res.first!=ortalar || ( last-arr[r])!=res.first  )){
                                // cout<<ferq<<" error:"<< ortalar<<" "<<last<<" "<<arr[r]<<" "<<res.first<<endl;
                                flag=false;
                                break;
                            }
                        }
                    }
                }
                last=arr[l];
            }
        }

        if(ranges.back()!=0 && flag){
            int l = 0;
            int r = ranges.back()-2;
            if(r<l){
                if(last!=-1){
                    if(ortalar!=-1){
                        if((last-arr[0]) != ortalar ){
                            // cout<<ferq<<" error"<<endl;
                            flag=false;
                        }
                    }
                }
            }
            else{
                pair<int,int> res = qry(l,r);
                if(last!=-1){
                    if(ortalar==-1){
                        if( ( res.first!=res.second || (last - arr[r+1])!=res.first )){
                            // cout<<ferq<<" error"<<endl;
                            // cout<<res.first<<" "<<res.second<<" "<<l<<","<<r<<" "<<last<<" "<<arr[r+1]<<" "<<(res.first!=res.second)<<endl;
                            flag=false;
                        }
                    }
                    else{
                        if(( res.first!=res.second || res.first!=ortalar || (last - arr[r+1])!=ortalar)){
                            flag=false;
                        }
                    }
                }
                else{
                    if(res.first!=res.second){
                        flag=false;
                    }
                }
            }
        }

        
        if(flag){
            // cout<<ferq<<" => \n";
            // for(auto v:ranges) cout<<v<<" ";cout<<"\n";
            vector<int> a,b;
            map<int,int> used;
            reverse(all(ranges));
            for(auto v:ranges){
                used[v]=1;
                a.pb(arr[v]);
            }
            for(int j=0;j<n;j++){
                if(!used[j]){
                    b.pb(arr[j]);
                }
            }
            if(b.empty()){
                b.pb(a.back());
                a.pop_back();
            }
            cout<<a.size()<<"\n";
            for(auto v:a)cout<<v<<" ";cout<<endl;
            cout<<b.size()<<"\n";
            for(auto v:b)cout<<v<<" ";cout<<endl;

            return;
        }
    }


    putr(-1);

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int tt = 1;
    // cin>>tt;
    while(tt--){
        opt1z();
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

drvca.cpp: In function 'void opt1z()':
drvca.cpp:65:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   65 |                 for(auto v:alst) cout<<v<<" ";cout<<"\n";
      |                 ^~~
drvca.cpp:65:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   65 |                 for(auto v:alst) cout<<v<<" ";cout<<"\n";
      |                                               ^~~~
drvca.cpp:67:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   67 |                 for(auto v:blst) cout<<v<<" ";cout<<"\n";
      |                 ^~~
drvca.cpp:67:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   67 |                 for(auto v:blst) cout<<v<<" ";cout<<"\n";
      |                                               ^~~~
drvca.cpp:75:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   75 |             for(auto v:alst) cout<<v<<" ";cout<<"\n";
      |             ^~~
drvca.cpp:75:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   75 |             for(auto v:alst) cout<<v<<" ";cout<<"\n";
      |                                           ^~~~
drvca.cpp:77:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   77 |             for(auto v:blst) cout<<v<<" ";cout<<"\n";
      |             ^~~
drvca.cpp:77:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   77 |             for(auto v:blst) cout<<v<<" ";cout<<"\n";
      |                                           ^~~~
drvca.cpp:87:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int i=1;i+1<tmp.size();i++){
      |                 ~~~^~~~~~~~~~~
drvca.cpp:95:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   95 |         for(auto v:tmp) cout<<v<<" "; cout<<endl;
      |         ^~~
drvca.cpp:95:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   95 |         for(auto v:tmp) cout<<v<<" "; cout<<endl;
      |                                       ^~~~
drvca.cpp:247:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  247 |             for(auto v:a)cout<<v<<" ";cout<<endl;
      |             ^~~
drvca.cpp:247:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  247 |             for(auto v:a)cout<<v<<" ";cout<<endl;
      |                                       ^~~~
drvca.cpp:249:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  249 |             for(auto v:b)cout<<v<<" ";cout<<endl;
      |             ^~~
drvca.cpp:249:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  249 |             for(auto v:b)cout<<v<<" ";cout<<endl;
      |                                       ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...