Submission #957269

# Submission time Handle Problem Language Result Execution time Memory
957269 2024-04-03T11:08:29 Z Nika533 Rope (JOI17_rope) C++17
80 / 100
2500 ms 96880 KB
#pragma gcc diagnostic "-std=c++1z"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
using namespace std;
const int N=1e6+5;
int n,m,T,k,arr[N],ans[N];
int t[N*4];
vector<int> pos[N];
void build(int v, int tl, int tr) {
     if (tl==tr) {
          t[v]=pos[tl].size();
          return;
     }
     int mid=(tl+tr)/2;
     build(v*2,tl,mid); build(v*2+1,mid+1,tr);
     t[v]=max(t[v*2],t[v*2+1]);
}
void update(int v, int tl, int tr, int ind, int val) {
     if (ind<tl || ind>tr) return;
     if (tl==tr) {
          t[v]+=val;
          return;
     }
     int mid=(tl+tr)/2;
     update(v*2,tl,mid,ind,val); update(v*2+1,mid+1,tr,ind,val);
     t[v]=max(t[v*2],t[v*2+1]);
}
void solve(int st) {
     build(1,1,m);
     for (int i=1; i<=m; i++) {
          int freq=pos[i].size();
          vector<int> p;
          for (auto j:pos[i]) {
               int o;
               if ((st+j)%2) o=j-1;
               else o=j+1;
               if (arr[o]!=0 && arr[o]!=i) p.pb(arr[o]);
               p.pb(arr[j]);
          }
          for (auto x:p) update(1,1,m,x,-1);
          int mx=t[1];
          ans[i]=min(ans[i],n-mx-freq);
          for (auto x:p) update(1,1,m,x,1);
     }
}
void test_case() {
     cin>>n>>m;
     for (int i=1; i<=n; i++) {
          cin>>arr[i];
          pos[arr[i]].pb(i);
     }
     for (int i=1; i<=m; i++) ans[i]=1e9;
     solve(0); solve(1);
     for (int i=1; i<=m; i++) cout<<ans[i]<<endl;
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1; 
	while (T--) test_case();
}

Compilation message

rope.cpp:1: warning: ignoring '#pragma gcc diagnostic' [-Wunknown-pragmas]
    1 | #pragma gcc diagnostic "-std=c++1z"
      | 
rope.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 6 ms 29328 KB Output is correct
9 Correct 6 ms 29300 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 6 ms 29304 KB Output is correct
15 Correct 6 ms 29272 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29288 KB Output is correct
20 Correct 7 ms 29272 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 6 ms 29324 KB Output is correct
23 Correct 7 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 6 ms 29328 KB Output is correct
9 Correct 6 ms 29300 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 6 ms 29304 KB Output is correct
15 Correct 6 ms 29272 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29288 KB Output is correct
20 Correct 7 ms 29272 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 6 ms 29324 KB Output is correct
23 Correct 7 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
27 Correct 33 ms 31136 KB Output is correct
28 Correct 24 ms 31220 KB Output is correct
29 Correct 31 ms 31036 KB Output is correct
30 Correct 27 ms 31208 KB Output is correct
31 Correct 36 ms 31068 KB Output is correct
32 Correct 24 ms 31172 KB Output is correct
33 Correct 31 ms 31256 KB Output is correct
34 Correct 27 ms 31148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 6 ms 29328 KB Output is correct
9 Correct 6 ms 29300 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 6 ms 29304 KB Output is correct
15 Correct 6 ms 29272 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29288 KB Output is correct
20 Correct 7 ms 29272 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 6 ms 29324 KB Output is correct
23 Correct 7 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
27 Correct 33 ms 31136 KB Output is correct
28 Correct 24 ms 31220 KB Output is correct
29 Correct 31 ms 31036 KB Output is correct
30 Correct 27 ms 31208 KB Output is correct
31 Correct 36 ms 31068 KB Output is correct
32 Correct 24 ms 31172 KB Output is correct
33 Correct 31 ms 31256 KB Output is correct
34 Correct 27 ms 31148 KB Output is correct
35 Correct 71 ms 30876 KB Output is correct
36 Correct 70 ms 30884 KB Output is correct
37 Correct 69 ms 30808 KB Output is correct
38 Correct 69 ms 30808 KB Output is correct
39 Correct 70 ms 30876 KB Output is correct
40 Correct 65 ms 31044 KB Output is correct
41 Correct 65 ms 30812 KB Output is correct
42 Correct 62 ms 30812 KB Output is correct
43 Correct 59 ms 31068 KB Output is correct
44 Correct 66 ms 30812 KB Output is correct
45 Correct 68 ms 31068 KB Output is correct
46 Correct 62 ms 30808 KB Output is correct
47 Correct 59 ms 31068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 6 ms 29328 KB Output is correct
9 Correct 6 ms 29300 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 6 ms 29304 KB Output is correct
15 Correct 6 ms 29272 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29288 KB Output is correct
20 Correct 7 ms 29272 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 6 ms 29324 KB Output is correct
23 Correct 7 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
27 Correct 33 ms 31136 KB Output is correct
28 Correct 24 ms 31220 KB Output is correct
29 Correct 31 ms 31036 KB Output is correct
30 Correct 27 ms 31208 KB Output is correct
31 Correct 36 ms 31068 KB Output is correct
32 Correct 24 ms 31172 KB Output is correct
33 Correct 31 ms 31256 KB Output is correct
34 Correct 27 ms 31148 KB Output is correct
35 Correct 71 ms 30876 KB Output is correct
36 Correct 70 ms 30884 KB Output is correct
37 Correct 69 ms 30808 KB Output is correct
38 Correct 69 ms 30808 KB Output is correct
39 Correct 70 ms 30876 KB Output is correct
40 Correct 65 ms 31044 KB Output is correct
41 Correct 65 ms 30812 KB Output is correct
42 Correct 62 ms 30812 KB Output is correct
43 Correct 59 ms 31068 KB Output is correct
44 Correct 66 ms 30812 KB Output is correct
45 Correct 68 ms 31068 KB Output is correct
46 Correct 62 ms 30808 KB Output is correct
47 Correct 59 ms 31068 KB Output is correct
48 Correct 915 ms 53760 KB Output is correct
49 Correct 863 ms 53588 KB Output is correct
50 Correct 862 ms 54060 KB Output is correct
51 Correct 774 ms 53304 KB Output is correct
52 Correct 713 ms 50596 KB Output is correct
53 Correct 799 ms 52304 KB Output is correct
54 Correct 798 ms 50260 KB Output is correct
55 Correct 782 ms 50000 KB Output is correct
56 Correct 788 ms 49320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 6 ms 29328 KB Output is correct
9 Correct 6 ms 29300 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 6 ms 29304 KB Output is correct
15 Correct 6 ms 29272 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29288 KB Output is correct
20 Correct 7 ms 29272 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 6 ms 29324 KB Output is correct
23 Correct 7 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
27 Correct 33 ms 31136 KB Output is correct
28 Correct 24 ms 31220 KB Output is correct
29 Correct 31 ms 31036 KB Output is correct
30 Correct 27 ms 31208 KB Output is correct
31 Correct 36 ms 31068 KB Output is correct
32 Correct 24 ms 31172 KB Output is correct
33 Correct 31 ms 31256 KB Output is correct
34 Correct 27 ms 31148 KB Output is correct
35 Correct 71 ms 30876 KB Output is correct
36 Correct 70 ms 30884 KB Output is correct
37 Correct 69 ms 30808 KB Output is correct
38 Correct 69 ms 30808 KB Output is correct
39 Correct 70 ms 30876 KB Output is correct
40 Correct 65 ms 31044 KB Output is correct
41 Correct 65 ms 30812 KB Output is correct
42 Correct 62 ms 30812 KB Output is correct
43 Correct 59 ms 31068 KB Output is correct
44 Correct 66 ms 30812 KB Output is correct
45 Correct 68 ms 31068 KB Output is correct
46 Correct 62 ms 30808 KB Output is correct
47 Correct 59 ms 31068 KB Output is correct
48 Correct 915 ms 53760 KB Output is correct
49 Correct 863 ms 53588 KB Output is correct
50 Correct 862 ms 54060 KB Output is correct
51 Correct 774 ms 53304 KB Output is correct
52 Correct 713 ms 50596 KB Output is correct
53 Correct 799 ms 52304 KB Output is correct
54 Correct 798 ms 50260 KB Output is correct
55 Correct 782 ms 50000 KB Output is correct
56 Correct 788 ms 49320 KB Output is correct
57 Execution timed out 2542 ms 96880 KB Time limit exceeded
58 Halted 0 ms 0 KB -