Submission #756508

# Submission time Handle Problem Language Result Execution time Memory
756508 2023-06-11T18:30:55 Z michao Stone Arranging 2 (JOI23_ho_t1) C++17
100 / 100
634 ms 63692 KB
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2e5+5;
int a[MAX];
set<pair<pii,int>>q;
map<int,int>conv;
set<int>pom;
int reconv[MAX];
set<pii>segs[MAX];

void add(int l,int r,int c){
  q.ins(mp(mp(l,r),c));
  segs[conv[c]].ins(mp(l,r));
}

void del(int l,int r,int c){
  q.erase(mp(mp(l,r),c));
  segs[conv[c]].erase(mp(l,r));
}
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
  for (int i=1;i<=n;i++)cin>>a[i];
  for (int i=1;i<=n;i++)pom.ins(a[i]);
  int cnt=1;
  for (auto it:pom){
    reconv[cnt]=it;
    conv[it]=cnt;
    cnt++;
  }
  for (int i=1;i<=n;i++){
    int colorcnv=conv[a[i]];
    if (segs[colorcnv].empty()){
      add(i,i,a[i]);
    }
    else{
      int l=segs[colorcnv].rbegin()->st;
      int r=i;
      while (!q.empty()){
        pair<pii,int>akt=*q.rbegin();
        int l2=akt.st.st;
        int r2=akt.st.nd;
        int color=akt.nd;
        if (r2<l)break;
        if (l2>=l){
          del(l2,r2,color);
          q.erase(akt);
          continue;
        }
        else{
          assert(r2>=l && l2<l);
          del(l2,r2,color);
          assert(color!=a[i]);
          add(l2,l-1,color);
        }
      }
      add(l,r,a[i]);
    }
  }
  for (auto it:q){
    for (int i=it.st.st;i<=it.st.nd;i++)cout<<it.nd<<"\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9732 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9732 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9736 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9748 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 6 ms 9732 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 8 ms 9684 KB Output is correct
17 Correct 7 ms 10252 KB Output is correct
18 Correct 9 ms 10196 KB Output is correct
19 Correct 8 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 8 ms 9684 KB Output is correct
22 Correct 6 ms 9744 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 6 ms 9740 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 6 ms 9732 KB Output is correct
27 Correct 5 ms 9736 KB Output is correct
28 Correct 6 ms 9732 KB Output is correct
29 Correct 7 ms 10000 KB Output is correct
30 Correct 7 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9732 KB Output is correct
2 Correct 7 ms 9652 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 7 ms 9684 KB Output is correct
5 Correct 7 ms 9736 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9636 KB Output is correct
8 Correct 5 ms 9732 KB Output is correct
9 Correct 8 ms 9684 KB Output is correct
10 Correct 6 ms 9732 KB Output is correct
11 Correct 6 ms 9728 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 7 ms 9684 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 6 ms 9720 KB Output is correct
17 Correct 42 ms 11992 KB Output is correct
18 Correct 43 ms 12032 KB Output is correct
19 Correct 49 ms 12000 KB Output is correct
20 Correct 48 ms 11904 KB Output is correct
21 Correct 48 ms 12036 KB Output is correct
22 Correct 48 ms 12028 KB Output is correct
23 Correct 57 ms 12048 KB Output is correct
24 Correct 51 ms 12008 KB Output is correct
25 Correct 47 ms 12028 KB Output is correct
26 Correct 51 ms 12044 KB Output is correct
27 Correct 51 ms 11980 KB Output is correct
28 Correct 48 ms 12040 KB Output is correct
29 Correct 46 ms 11992 KB Output is correct
30 Correct 46 ms 11780 KB Output is correct
31 Correct 44 ms 12048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9732 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9732 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 6 ms 9736 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9748 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 6 ms 9732 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 8 ms 9684 KB Output is correct
17 Correct 7 ms 10252 KB Output is correct
18 Correct 9 ms 10196 KB Output is correct
19 Correct 8 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 8 ms 9684 KB Output is correct
22 Correct 6 ms 9744 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 6 ms 9740 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 6 ms 9732 KB Output is correct
27 Correct 5 ms 9736 KB Output is correct
28 Correct 6 ms 9732 KB Output is correct
29 Correct 7 ms 10000 KB Output is correct
30 Correct 7 ms 9940 KB Output is correct
31 Correct 5 ms 9732 KB Output is correct
32 Correct 7 ms 9652 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 7 ms 9684 KB Output is correct
35 Correct 7 ms 9736 KB Output is correct
36 Correct 5 ms 9684 KB Output is correct
37 Correct 5 ms 9636 KB Output is correct
38 Correct 5 ms 9732 KB Output is correct
39 Correct 8 ms 9684 KB Output is correct
40 Correct 6 ms 9732 KB Output is correct
41 Correct 6 ms 9728 KB Output is correct
42 Correct 6 ms 9684 KB Output is correct
43 Correct 7 ms 9684 KB Output is correct
44 Correct 6 ms 9684 KB Output is correct
45 Correct 6 ms 9684 KB Output is correct
46 Correct 6 ms 9720 KB Output is correct
47 Correct 42 ms 11992 KB Output is correct
48 Correct 43 ms 12032 KB Output is correct
49 Correct 49 ms 12000 KB Output is correct
50 Correct 48 ms 11904 KB Output is correct
51 Correct 48 ms 12036 KB Output is correct
52 Correct 48 ms 12028 KB Output is correct
53 Correct 57 ms 12048 KB Output is correct
54 Correct 51 ms 12008 KB Output is correct
55 Correct 47 ms 12028 KB Output is correct
56 Correct 51 ms 12044 KB Output is correct
57 Correct 51 ms 11980 KB Output is correct
58 Correct 48 ms 12040 KB Output is correct
59 Correct 46 ms 11992 KB Output is correct
60 Correct 46 ms 11780 KB Output is correct
61 Correct 44 ms 12048 KB Output is correct
62 Correct 54 ms 15148 KB Output is correct
63 Correct 564 ms 48368 KB Output is correct
64 Correct 579 ms 45692 KB Output is correct
65 Correct 61 ms 14836 KB Output is correct
66 Correct 58 ms 14760 KB Output is correct
67 Correct 65 ms 15160 KB Output is correct
68 Correct 59 ms 14684 KB Output is correct
69 Correct 64 ms 13644 KB Output is correct
70 Correct 68 ms 14984 KB Output is correct
71 Correct 68 ms 14952 KB Output is correct
72 Correct 64 ms 14192 KB Output is correct
73 Correct 357 ms 39212 KB Output is correct
74 Correct 323 ms 39364 KB Output is correct
75 Correct 452 ms 63232 KB Output is correct
76 Correct 634 ms 63692 KB Output is correct
77 Correct 477 ms 63692 KB Output is correct
78 Correct 493 ms 62384 KB Output is correct