Submission #634446

# Submission time Handle Problem Language Result Execution time Memory
634446 2022-08-24T12:26:09 Z alvingogo Copy and Paste 3 (JOI22_copypaste3) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;

int main(){
    AquA;
    int n;
    cin >> n;
    vector<pair<int,pair<int,int> > > v(n);
    int ans=-1,my=0,mz=0;
    set<pair<int,int> > s;
    for(int i=0;i<n;i++){
        cin >> v[i].fs >> v[i].sc.fs >> v[i].sc.sc;
    }
    sort(v.begin(),v.end());
    vector<pair<int,int> > g;
    for(int i=0;i<n;i++){
        auto h=v[i].sc;
        if(my>h.fs && mz>h.sc){
            ans=max(ans,v[i].fs+my+mz);
        }
        g.push_back(h);
        if(i==n-1 || v[i].fs!=v[i+1].fs){
            for(auto t:g){
                if(s.empty()){
                    if(my<=t.fs && mz<=t.sc){
                        s.insert(t);
                    }
                    else{
                        my=max(my,t.fs);
                        mz=max(mz,t.sc);
                    }
                    continue;
                }
                auto y=s.lower_bound(t);
                auto z=prev(y);
                if((y==s.end() || ((*y).fs>=t.fs && (*y).sc>=t.sc)) && (y==s.begin() || (*z).fs<=t.fs && (*z).sc<=t.sc)){
                    if(my<=t.fs && mz<=t.sc){
                        s.insert(t);
                    }
                    else{
                        my=max(my,t.fs);
                        mz=max(mz,t.sc);
                    }
                }
                else{
                    for(auto it=s.begin();it!=s.end();it=s.erase(it)){
                        if((*it).fs>=t.fs && (*it).sc>=t.sc){
                            break;
                        }
                        my=max(my,(*it).fs);
                        mz=max(mz,(*it).sc);
                    }
                    my=max(my,t.fs);
                    mz=max(mz,t.sc);
                }
            }
            g.clear();
        }
    }
    cout << ans << "\n";
    return 0;
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:41:103: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   41 |                 if((y==s.end() || ((*y).fs>=t.fs && (*y).sc>=t.sc)) && (y==s.begin() || (*z).fs<=t.fs && (*z).sc<=t.sc)){
      |                                                                                                       ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -