Submission #1304764

#TimeUsernameProblemLanguageResultExecution timeMemory
1304764sitingfakeTeam Contest (JOI22_team)C++20
64 / 100
128 ms8000 KiB
#include<bits/stdc++.h> using namespace std; // define //bool M1; //#define execute cerr << " Time: " << fixed << setprecision(6) << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n"; //#define memory cerr << abs(&M2 - &M1)/1024.0/1024 << " MB" << "\n" #define ll long long #define ii pair <int , int> #define iii pair <int , ii> #define se second #define fi first #define all(v) (v).begin() , (v).end() #define Unique(v) sort(all(v)) , v.resize(unique(all(v)) - v.begin()) #define bit(x,i) (((x) >> (i)) & 1LL) #define flip(x,i) ((x) ^ (1LL << (i))) #define ms(d,x) memset(d , x , sizeof(d)) #define exist __exist #define ends __ends #define visit visited #define left __left #define right __right #define prev __prev #define next __next #define sitingfake 1 #define orz 1 //constant const long long mod = 1e9 + 7; const long long linf = 4557430888798830399LL; const long long nlinf = -4485090715960753727LL; const int inf = 1061109567; const int ninf = -1044266559; const int dx[] = {0 , -1 , 0 , 1}; const int dy[] = {-1 , 0 , 1 , 0}; template<typename T> bool maximize(T &a, const T &b) { if(a < b) {a = b; return 1;} return 0; } template<typename T> bool minimize(T &a, const T &b) { if(a > b) {a = b; return 1;} return 0; } void Plus(ll & a ,ll b) { b %= mod; a += b; if(a < 0) a += mod; a %= mod; return; } void Mul(ll & a, ll b) { (a *= (b % mod)) %= mod; return; } //code const int maxn = 150005; int n; struct Beaver { int x , y , z; }a[maxn]; namespace sub2 { struct BIT { int bit[4005]; BIT() { ms(bit , 0); } void up(int x , int val) { for(;x <= n; x += (x & -x)) { bit[x] = max(bit[x] , val); } } int get(int x) { int ans = 0; for(;x > 0; x -= (x & -x)) { ans = max(ans , bit[x]); } return ans; } }; vector <int> py , pz; int posy[4004] , posz[4004]; void compress() { for(int i = 1; i <= n; i++) { py.push_back(a[i].y); pz.push_back(a[i].z); } Unique(py); Unique(pz); for(int i = 1; i <= n; i++) { posy[i] = lower_bound(all(py) , a[i].y) - py.begin() + 1; posz[i] = lower_bound(all(pz) , a[i].z) - pz.begin() + 1; } } bool cmp(Beaver &a , Beaver &b) { return a.x < b.x; } void solve() { sort(a + 1 , a + n + 1 , cmp); compress(); BIT bitY , bitZ; int it = 1; int ans = -1; for(int i = 1; i <= n; i++) { while(it < i && a[it].x < a[i].x) { bitY.up(posy[it] , a[it].z); bitZ.up(posz[it] , a[it].y); it++; } for(int j = i - 1; j >= 1; j--) { if(a[i].x > a[j].x) { if(a[j].y > a[i].y) { int val = bitY.get(posy[j] - 1); if(val > max(a[i].z , a[j].z)) { ans = max(ans , a[i].x + a[j].y + val); } } if(a[j].z > a[i].z) { int val = bitZ.get(posz[j] - 1); if(val > max(a[i].y , a[j].y)) { ans = max(ans , a[i].x + a[j].z + val); } } } } } cout << ans; } } namespace sub5 { int MinY[4040] , MinZ[4040]; vector <ii> Point[4004]; bool approve() { for(int i = 1; i <= n; i++) { if(a[i].x > 300) return 0; else if(a[i].y > 300) return 0; else if(a[i].z > 300) return 0; } return 1; } void solve() { for(int i = 1; i <= n; i++) { Point[a[i].x].push_back({a[i].y , a[i].z}); } for(int i = 1; i <= 300; i++) { sort(all(Point[i])); } ms(MinY , 0x3f); ms(MinZ , 0x3f); int ans = -1; for(int x = 1; x <= 300; x++) { int mi = inf; int it = 0; if(Point[x].empty()) continue; for(int y = 1; y <= 300; y++) { while(it < Point[x].size() && Point[x][it].fi < y) { mi = min(mi , Point[x][it].se); ++it; } int LimZ = max(mi , MinZ[y]); for(int z = LimZ + 1; z <= 300; z++) { if(MinY[z] < y) { ans = max(ans , x + y + z); } } } for(ii it : Point[x]) { MinY[it.se] = min(MinY[it.se] , it.fi); MinZ[it.fi] = min(MinZ[it.fi] , it.se); } } cout << ans; } } namespace sub7 { int idx[maxn] , idy[maxn] , idz[maxn]; int numx , numy , numz; void compress() { vector <int> px , py , pz; for(int i = 1; i <= n; i++) { px.push_back(a[i].x); py.push_back(a[i].y); pz.push_back(a[i].z); } Unique(px); Unique(py); Unique(pz); for(int i = 1; i <= n; i++) { a[i].x = lower_bound(all(px) , a[i].x) - px.begin() + 1; a[i].y = lower_bound(all(py) , a[i].y) - py.begin() + 1; a[i].z = lower_bound(all(pz) , a[i].z) - pz.begin() + 1; } numx = px.size(); numy = py.size(); numz = pz.size(); for(int i = 0; i < px.size(); i++) { idx[i + 1] = px[i]; } for(int i = 0; i < py.size(); i++) { idy[i + 1] = py[i]; } for(int i = 0; i < pz.size(); i++) { idz[i + 1] = pz[i]; } } vector <ii> Point[maxn]; bool cmp(ii &a , ii &b) { return a.se < b.se; } struct BIT { int bit[maxn]; BIT () { ms(bit , 0); } void up(int x , int val) { for(;x <= n; x += (x & -x)) { bit[x] = max(bit[x] , val); } } int get(int x) { int ans = 0; for(;x > 0; x -= (x & -x)) { ans = max(ans , bit[x]); } return ans; } }; struct BITPAIR { vector <ii> bit; int sz = 0; BITPAIR (int n) { sz = n; bit.resize(n + 3); for(int i = 0; i <= sz; i++) bit[i] = {0 , 0}; } void up(int x , int pos , int val) { for(;x > 0; x -= (x & -x)) { bit[x] = max(bit[x] , {val , pos}); } } ii get(int x) { ii ans = {0 , 0}; for(;x <= sz; x += (x & -x)) { ans = max(ans , bit[x]); } return ans; } }; void solve() { //cout << 11111 << endl; compress(); for(int i = 1; i <= n; i++) { Point[a[i].x].push_back({a[i].y , a[i].z}); } int ans = -1; BIT bitY , bitZ; BITPAIR BY(n) , BZ(n); for(int x = 1; x <= numx; x++) { sort(all(Point[x])); for(ii it : Point[x]) { ii val = BY.get(it.fi + 1); if(val.se > it.se) { ans = max(ans , idx[x] + idy[val.se] + idz[val.fi]); } val = BZ.get(it.se + 1); if(val.se > it.fi) { ans = max(ans , idx[x] + idy[val.fi] + idz[val.se]); } } int it = 0; for(int j = 0; j < Point[x].size(); j++) { while(it < j && Point[x][it].fi < Point[x][j].fi) { bitY.up(Point[x][it].fi , Point[x][it].se); it++; } int Max = bitY.get(Point[x][j].fi - 1); if(Max > Point[x][j].se) { BY.up(Point[x][j].fi , Point[x][j].fi , Max); } } for(int j = it ; j < Point[x].size(); j++) { bitY.up(Point[x][it].fi , Point[x][it].se); } sort(all(Point[x]) , cmp); it = 0; for(int j = 0; j < Point[x].size(); j++) { while(it < j && Point[x][it].se < Point[x][j].se) { bitZ.up(Point[x][it].se , Point[x][it].fi); it++; } int Max = bitZ.get(Point[x][j].se - 1); if(Max > Point[x][j].fi) { BZ.up(Point[x][j].se , Point[x][j].se , Max); } } for(int j = it ; j < Point[x].size(); j++) { bitZ.up(Point[x][it].se , Point[x][it].fi); } } cout << ans; } } void solve(void) { cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i].x >> a[i].y >> a[i].z; } if(n <= 4000) return sub2 :: solve(); if(sub5 :: approve()) return sub5 :: solve(); sub7 :: solve(); } /** **/ //bool M2; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int tc = 1; // cin >> tc; while(tc--) solve(); // execute; // memory; }

Compilation message (stderr)

team.cpp: In function 'int main()':
team.cpp:440:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  440 |        freopen(task".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
team.cpp:441:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  441 |        freopen(task".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...