답안 #724521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724521 2023-04-15T13:16:25 Z MohammadAghil Team Contest (JOI22_team) C++17
37 / 100
2000 ms 7552 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define all(x) begin(x), end(x)
#define sz(x) (int)size(x)
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> pp;

void dbg(){
     cerr << endl;
}
template<typename H, typename... T> void dbg(H h, T... t){
     cerr << h << ", ";
     dbg(t...);
}

void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     #ifndef ONLINE_JUDGE
          // freopen("inp.txt", "r", stdin);
          // freopen("out.txt", "w", stdout);
          #define er(...) cerr << __LINE__ << " <" << #__VA_ARGS__ << ">: ", dbg(__VA_ARGS__)
     #else
          #define er(...) 0
     #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 998244353, maxn = 5e5 + 5, lg = 21, inf = ll(1e9) + 5;

struct Fen{
     vector<int> fen;
     Fen(){}
     Fen(int n){
          fen.assign(n + 1, -inf);
     }
     void upd(int i, int k){
          for(i++; i < sz(fen); i += i&-i) fen[i] = max(fen[i], k);
     }
     int get(int i){
          int res = -inf;
          for(i++; i; i -= i&-i) res = max(res, fen[i]);
          return res;
     }
} prf, suf;

int n, x[maxn], y[maxn], z[maxn];
int X = -1, Y = -1, id;
map<int, int> mp;

multiset<pp> s;

void add(int x, int y){
     er(x, y);
     // for(auto[x, y]: s){
     //      er(x, y);
     // }
     vector<pp> del;
     auto it = s.lower_bound(pp(x, -1));
     while(it != begin(s)){
          it--;
          if(it->ss <= y) break;
          del.pb(*it);
     }
     auto it2 = s.upper_bound(pp(x, inf));
     while(it2 != end(s)){
          if(it2->ss >= y) break;
          del.pb(*it2);
          it2++;
     }
     auto add2 = [&](int x, int y){
          er(x, y);
          X = max(X, x), Y = max(Y, y);
          prf.upd(mp[x], y);
          suf.upd(id-mp[x]-1, -y);
     };
     if(del.empty()){
          if(prf.get(mp[x]-1) > y) add2(x, y);
          else {
               if(-suf.get(id-1-mp[x]-1) < y) add2(x, y);
               else s.insert({x, y});
          }
     } else{
          add2(x, y);
          for(auto p: del){
               // er(p.ff, p.ss);
               auto it = s.find(p);
               add2(p.ff, p.ss);
               s.erase(it);
          }
     }
}

int slv1(){
     s.clear(), X = Y = -1, mp.clear();
     map<int, vector<pp>> mpp;
     rep(i,0,n){
          mpp[z[i]].pb({x[i], y[i]});
          mp[x[i]] = 0;
     }
     for(auto&c: mp) c.ss = id++;
     prf = Fen(id);
     suf = Fen(id);
     int ans = -1;
     for(auto[Z, v]: mpp){
          for(auto[x, y]: v){
               if(X > x && Y > y){
                    ans = max(ans, Z + X + Y);
               }
          }
          for(auto[x, y]: v){
               add(x, y);
          }
     }
     return ans;
}


int main(){ IOS();
     cin >> n;
     rep(i,0,n){
          cin >> x[i] >> y[i] >> z[i];
     }
     cout << slv1() << '\n';
     return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 7 ms 420 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 6 ms 340 KB Output is correct
17 Correct 7 ms 340 KB Output is correct
18 Correct 8 ms 388 KB Output is correct
19 Correct 7 ms 372 KB Output is correct
20 Correct 6 ms 368 KB Output is correct
21 Correct 6 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 7 ms 420 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 6 ms 340 KB Output is correct
17 Correct 7 ms 340 KB Output is correct
18 Correct 8 ms 388 KB Output is correct
19 Correct 7 ms 372 KB Output is correct
20 Correct 6 ms 368 KB Output is correct
21 Correct 6 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 92 ms 1556 KB Output is correct
27 Correct 91 ms 1096 KB Output is correct
28 Correct 91 ms 1096 KB Output is correct
29 Correct 85 ms 1016 KB Output is correct
30 Correct 60 ms 716 KB Output is correct
31 Correct 84 ms 816 KB Output is correct
32 Correct 85 ms 740 KB Output is correct
33 Correct 62 ms 972 KB Output is correct
34 Correct 49 ms 1372 KB Output is correct
35 Correct 11 ms 468 KB Output is correct
36 Correct 10 ms 448 KB Output is correct
37 Correct 44 ms 1024 KB Output is correct
38 Correct 46 ms 884 KB Output is correct
39 Correct 46 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 2076 ms 7552 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 2076 ms 7552 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 2076 ms 7552 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 2076 ms 7552 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 7 ms 420 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 6 ms 340 KB Output is correct
17 Correct 7 ms 340 KB Output is correct
18 Correct 8 ms 388 KB Output is correct
19 Correct 7 ms 372 KB Output is correct
20 Correct 6 ms 368 KB Output is correct
21 Correct 6 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 92 ms 1556 KB Output is correct
27 Correct 91 ms 1096 KB Output is correct
28 Correct 91 ms 1096 KB Output is correct
29 Correct 85 ms 1016 KB Output is correct
30 Correct 60 ms 716 KB Output is correct
31 Correct 84 ms 816 KB Output is correct
32 Correct 85 ms 740 KB Output is correct
33 Correct 62 ms 972 KB Output is correct
34 Correct 49 ms 1372 KB Output is correct
35 Correct 11 ms 468 KB Output is correct
36 Correct 10 ms 448 KB Output is correct
37 Correct 44 ms 1024 KB Output is correct
38 Correct 46 ms 884 KB Output is correct
39 Correct 46 ms 448 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Execution timed out 2076 ms 7552 KB Time limit exceeded
51 Halted 0 ms 0 KB -