답안 #556247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556247 2022-05-02T15:59:40 Z 600Mihnea Team Contest (JOI22_team) C++17
100 / 100
836 ms 38008 KB
#include <bits/stdc++.h>

bool home = 1;

using namespace std;

struct T {
  int x;
  int y;
  int z;
  int tx;
  int ty;
  int tz;
};

bool cmp_x_inv(T a,T b) {
  return a.x>b.x;
}

typedef long long ll;
const int N=150000+7;
const int INF=(int)1e9+7;
int n,zm[N],invy[N],invz[N],value[N];
T a[N];
int aib1[N];

void clr1() {
  for (int i=1;i<=n;i++) aib1[i]=-INF;
}

int get1(int i) {
  int sol=-INF;
  while (i) {
    sol=max(sol,aib1[i]);
    i-=i&(-i);
  }
  return sol;
}

void upd1(int i,int x) {
  while (i<=n){
    aib1[i]=max(aib1[i],x);
    i+=i&(-i);
  }
}

vector<int> values[N],aib[N];

void clr() {
  for (int i=1;i<=n;i++) values[i].clear(), aib[i].clear();
}

void upd(int x,int y,int val) {
  for (int i=x;i<=n;i+=i&(-i)) {
    int p=lower_bound(values[i].begin(),values[i].end(),y)-values[i].begin()+1;
    assert(1<=p&&p<(int)aib[i].size());
    assert(values[i][p-1]==y);

    for (int j=p;j<(int)aib[i].size();j+=j&(-j)) {
      aib[i][j]=max(aib[i][j],val);
    }
  }
}

int get(int x,int y) {
  int sol=-INF;
  for (int i=x;i>=1;i-=i&(-i)) {

    int low=0,high=(int)values[i].size()-1,p=0;

    while(low<=high){
      int mid=(low+high)/2;
      if(values[i][mid]<=y) {
        p=mid+1;
        low=mid+1;
      }else{
        high=mid-1;
      }
    }

    for (int j=p;j>=1;j-=j&(-j)) {
      sol=max(sol,aib[i][j]);
    }
  }
  return sol;
}

signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif

  home=0;

  if (home) {
    freopen("I_am_iron_man", "r", stdin);
  }
  else {
    ios::sync_with_stdio(0); cin.tie(0);
  }

  cin>>n;
  for (int i=1;i<=n;i++) {
    cin>>a[i].x>>a[i].y>>a[i].z;
  }
  sort(a+1,a+n+1,cmp_x_inv);
  {
    map<int, int> tx,ty,tz;
    for (int i=1;i<=n;i++) tx[a[i].x]=0,ty[a[i].y]=0,tz[a[i].z]=0;
    int ind;
    ind=0; for (auto &it:tx)it.second=++ind;
    ind=0; for (auto &it:ty)it.second=++ind, invy[ind]=it.first;
    ind=0; for (auto &it:tz)it.second=++ind, invz[ind]=it.first;
    for (int i=1;i<=n;i++) a[i].tx=tx[a[i].x], a[i].ty=ty[a[i].y], a[i].tz=tz[a[i].z];
  }
  int print=-1;

  for (int ITER=0;ITER<2;ITER++) {
    clr1();
    clr();

    for (int i=n;i>=1;i--) { /// optimize using aib
      zm[i]=get1(a[i].ty-1);
      upd1(a[i].ty,a[i].tz);
      if (zm[i]<=a[i].tz) zm[i]=-INF;

      if (1<=zm[i]&&zm[i]<=n) value[i]=invz[zm[i]]+a[i].y; else assert(zm[i]==-INF);
    }

    for (int i=1;i<=n;i++) {
      if(zm[i]==-INF) continue;
      int y=n+1-a[i].ty,z=n+1-zm[i];
      for (int p=y;p<=n;p+=p&(-p)) {
        values[p].push_back(z);
      }
    }

    for (int i=1;i<=n;i++) {

      sort(values[i].begin(), values[i].end());
      values[i].resize(unique(values[i].begin(), values[i].end())-values[i].begin());
      aib[i].resize((int)values[i].size()+1,-INF);
    }

    int last=n;
    while(last>=1){
      int first=last;
      while(first-1>=1&&a[first-1].x==a[first].x) first--;

      for (int i=first;i<=last;i++) {
        print=max(print,get(n-a[i].ty,n-a[i].tz)+a[i].x);
      }

      for (int i=first;i<=last;i++) {
        if (zm[i]!=-INF) {
          upd(n+1-a[i].ty,n+1-zm[i],value[i]);
        }
      }
      last=first-1;
    }
    for (int i=1;i<=n;i++) swap(a[i].y,a[i].z), swap(a[i].ty,a[i].tz), swap(invz[i],invy[i]);
  }

  cout<<print<<"\n";
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:96:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7328 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7372 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7328 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7372 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 11 ms 8088 KB Output is correct
27 Correct 11 ms 7892 KB Output is correct
28 Correct 12 ms 7892 KB Output is correct
29 Correct 11 ms 7824 KB Output is correct
30 Correct 8 ms 7636 KB Output is correct
31 Correct 11 ms 7836 KB Output is correct
32 Correct 8 ms 7764 KB Output is correct
33 Correct 7 ms 7732 KB Output is correct
34 Correct 8 ms 8148 KB Output is correct
35 Correct 6 ms 7520 KB Output is correct
36 Correct 4 ms 7508 KB Output is correct
37 Correct 7 ms 7764 KB Output is correct
38 Correct 7 ms 7764 KB Output is correct
39 Correct 5 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7384 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 94 ms 19328 KB Output is correct
12 Correct 62 ms 15052 KB Output is correct
13 Correct 61 ms 16148 KB Output is correct
14 Correct 85 ms 18820 KB Output is correct
15 Correct 77 ms 19224 KB Output is correct
16 Correct 63 ms 17880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7384 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 94 ms 19328 KB Output is correct
12 Correct 62 ms 15052 KB Output is correct
13 Correct 61 ms 16148 KB Output is correct
14 Correct 85 ms 18820 KB Output is correct
15 Correct 77 ms 19224 KB Output is correct
16 Correct 63 ms 17880 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7288 KB Output is correct
19 Correct 4 ms 7364 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 6 ms 7508 KB Output is correct
22 Correct 119 ms 20244 KB Output is correct
23 Correct 103 ms 19140 KB Output is correct
24 Correct 77 ms 16200 KB Output is correct
25 Correct 100 ms 19460 KB Output is correct
26 Correct 84 ms 19596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7384 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 94 ms 19328 KB Output is correct
12 Correct 62 ms 15052 KB Output is correct
13 Correct 61 ms 16148 KB Output is correct
14 Correct 85 ms 18820 KB Output is correct
15 Correct 77 ms 19224 KB Output is correct
16 Correct 63 ms 17880 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7288 KB Output is correct
19 Correct 4 ms 7364 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 6 ms 7508 KB Output is correct
22 Correct 119 ms 20244 KB Output is correct
23 Correct 103 ms 19140 KB Output is correct
24 Correct 77 ms 16200 KB Output is correct
25 Correct 100 ms 19460 KB Output is correct
26 Correct 84 ms 19596 KB Output is correct
27 Correct 5 ms 7380 KB Output is correct
28 Correct 5 ms 7380 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 10 ms 7764 KB Output is correct
32 Correct 5 ms 7508 KB Output is correct
33 Correct 5 ms 7516 KB Output is correct
34 Correct 168 ms 20920 KB Output is correct
35 Correct 161 ms 20032 KB Output is correct
36 Correct 171 ms 21100 KB Output is correct
37 Correct 147 ms 20040 KB Output is correct
38 Correct 92 ms 20428 KB Output is correct
39 Correct 74 ms 16208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7384 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 94 ms 19328 KB Output is correct
12 Correct 62 ms 15052 KB Output is correct
13 Correct 61 ms 16148 KB Output is correct
14 Correct 85 ms 18820 KB Output is correct
15 Correct 77 ms 19224 KB Output is correct
16 Correct 63 ms 17880 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7288 KB Output is correct
19 Correct 4 ms 7364 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 6 ms 7508 KB Output is correct
22 Correct 119 ms 20244 KB Output is correct
23 Correct 103 ms 19140 KB Output is correct
24 Correct 77 ms 16200 KB Output is correct
25 Correct 100 ms 19460 KB Output is correct
26 Correct 84 ms 19596 KB Output is correct
27 Correct 5 ms 7380 KB Output is correct
28 Correct 5 ms 7380 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 10 ms 7764 KB Output is correct
32 Correct 5 ms 7508 KB Output is correct
33 Correct 5 ms 7516 KB Output is correct
34 Correct 168 ms 20920 KB Output is correct
35 Correct 161 ms 20032 KB Output is correct
36 Correct 171 ms 21100 KB Output is correct
37 Correct 147 ms 20040 KB Output is correct
38 Correct 92 ms 20428 KB Output is correct
39 Correct 74 ms 16208 KB Output is correct
40 Correct 8 ms 7636 KB Output is correct
41 Correct 11 ms 7832 KB Output is correct
42 Correct 7 ms 7760 KB Output is correct
43 Correct 7 ms 7764 KB Output is correct
44 Correct 250 ms 23872 KB Output is correct
45 Correct 251 ms 21548 KB Output is correct
46 Correct 269 ms 22148 KB Output is correct
47 Correct 243 ms 21268 KB Output is correct
48 Correct 108 ms 20548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7328 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7372 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 11 ms 8088 KB Output is correct
27 Correct 11 ms 7892 KB Output is correct
28 Correct 12 ms 7892 KB Output is correct
29 Correct 11 ms 7824 KB Output is correct
30 Correct 8 ms 7636 KB Output is correct
31 Correct 11 ms 7836 KB Output is correct
32 Correct 8 ms 7764 KB Output is correct
33 Correct 7 ms 7732 KB Output is correct
34 Correct 8 ms 8148 KB Output is correct
35 Correct 6 ms 7520 KB Output is correct
36 Correct 4 ms 7508 KB Output is correct
37 Correct 7 ms 7764 KB Output is correct
38 Correct 7 ms 7764 KB Output is correct
39 Correct 5 ms 7508 KB Output is correct
40 Correct 6 ms 7384 KB Output is correct
41 Correct 4 ms 7380 KB Output is correct
42 Correct 4 ms 7380 KB Output is correct
43 Correct 4 ms 7380 KB Output is correct
44 Correct 4 ms 7380 KB Output is correct
45 Correct 4 ms 7380 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 4 ms 7380 KB Output is correct
48 Correct 4 ms 7380 KB Output is correct
49 Correct 4 ms 7380 KB Output is correct
50 Correct 94 ms 19328 KB Output is correct
51 Correct 62 ms 15052 KB Output is correct
52 Correct 61 ms 16148 KB Output is correct
53 Correct 85 ms 18820 KB Output is correct
54 Correct 77 ms 19224 KB Output is correct
55 Correct 63 ms 17880 KB Output is correct
56 Correct 4 ms 7380 KB Output is correct
57 Correct 4 ms 7288 KB Output is correct
58 Correct 4 ms 7364 KB Output is correct
59 Correct 4 ms 7380 KB Output is correct
60 Correct 6 ms 7508 KB Output is correct
61 Correct 119 ms 20244 KB Output is correct
62 Correct 103 ms 19140 KB Output is correct
63 Correct 77 ms 16200 KB Output is correct
64 Correct 100 ms 19460 KB Output is correct
65 Correct 84 ms 19596 KB Output is correct
66 Correct 5 ms 7380 KB Output is correct
67 Correct 5 ms 7380 KB Output is correct
68 Correct 4 ms 7380 KB Output is correct
69 Correct 4 ms 7380 KB Output is correct
70 Correct 10 ms 7764 KB Output is correct
71 Correct 5 ms 7508 KB Output is correct
72 Correct 5 ms 7516 KB Output is correct
73 Correct 168 ms 20920 KB Output is correct
74 Correct 161 ms 20032 KB Output is correct
75 Correct 171 ms 21100 KB Output is correct
76 Correct 147 ms 20040 KB Output is correct
77 Correct 92 ms 20428 KB Output is correct
78 Correct 74 ms 16208 KB Output is correct
79 Correct 8 ms 7636 KB Output is correct
80 Correct 11 ms 7832 KB Output is correct
81 Correct 7 ms 7760 KB Output is correct
82 Correct 7 ms 7764 KB Output is correct
83 Correct 250 ms 23872 KB Output is correct
84 Correct 251 ms 21548 KB Output is correct
85 Correct 269 ms 22148 KB Output is correct
86 Correct 243 ms 21268 KB Output is correct
87 Correct 108 ms 20548 KB Output is correct
88 Correct 836 ms 34884 KB Output is correct
89 Correct 613 ms 27608 KB Output is correct
90 Correct 645 ms 30748 KB Output is correct
91 Correct 414 ms 24908 KB Output is correct
92 Correct 418 ms 25804 KB Output is correct
93 Correct 574 ms 29208 KB Output is correct
94 Correct 435 ms 25036 KB Output is correct
95 Correct 163 ms 24716 KB Output is correct
96 Correct 248 ms 38008 KB Output is correct
97 Correct 86 ms 20448 KB Output is correct
98 Correct 130 ms 22736 KB Output is correct
99 Correct 145 ms 22752 KB Output is correct