답안 #957279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957279 2024-04-03T11:23:02 Z Nika533 Rope (JOI17_rope) C++14
80 / 100
2500 ms 105304 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],fix[N],fix2[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) {
     for (int i=1; i<=m; i++) {
          int freq=pos[i].size();
          vector<int> p;
          for (int oo=0; oo<pos[i].size(); oo++) {
               int j=pos[i][oo];
               int o;
               if ((st+j)%2) o=j-1;
               else o=j+1;
               if (arr[o]!=0 && arr[o]!=i) {
                    p.pb(arr[o]); fix[arr[o]]++; fix2[arr[o]]=1;
               }
          }
          for (auto x:p) {
               if (fix2[x]) {
                    update(1,1,m,x,-fix[x]);
                    fix2[x]=0;
               }
          }
          update(1,1,m,i,-freq);
          int mx=t[1];
          ans[i]=min(ans[i],n-mx-freq);
          for (auto x:p) {
               if (fix[x]) {
                    update(1,1,m,x,fix[x]);
                    fix[x]=0;
               }
          }
          update(1,1,m,i,freq);
     }
}
void test_case() {
     cin>>n>>m;
     for (int i=1; i<=n; i++) {
          cin>>arr[i];
          pos[arr[i]].pb(i);
     }
     build(1,1,m);
     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: In function 'void solve(long long int)':
rope.cpp:39:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |           for (int oo=0; oo<pos[i].size(); oo++) {
      |                          ~~^~~~~~~~~~~~~~
rope.cpp: At global scope:
rope.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   77 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33372 KB Output is correct
2 Correct 7 ms 33380 KB Output is correct
3 Correct 7 ms 33372 KB Output is correct
4 Correct 7 ms 33372 KB Output is correct
5 Correct 7 ms 33368 KB Output is correct
6 Correct 7 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 7 ms 33368 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 7 ms 33456 KB Output is correct
12 Correct 7 ms 33372 KB Output is correct
13 Correct 7 ms 33396 KB Output is correct
14 Correct 7 ms 33372 KB Output is correct
15 Correct 7 ms 33372 KB Output is correct
16 Correct 7 ms 33376 KB Output is correct
17 Correct 7 ms 33372 KB Output is correct
18 Correct 6 ms 33372 KB Output is correct
19 Correct 7 ms 33372 KB Output is correct
20 Correct 7 ms 33372 KB Output is correct
21 Correct 7 ms 33372 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 7 ms 33372 KB Output is correct
24 Correct 7 ms 33372 KB Output is correct
25 Correct 7 ms 33372 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33372 KB Output is correct
2 Correct 7 ms 33380 KB Output is correct
3 Correct 7 ms 33372 KB Output is correct
4 Correct 7 ms 33372 KB Output is correct
5 Correct 7 ms 33368 KB Output is correct
6 Correct 7 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 7 ms 33368 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 7 ms 33456 KB Output is correct
12 Correct 7 ms 33372 KB Output is correct
13 Correct 7 ms 33396 KB Output is correct
14 Correct 7 ms 33372 KB Output is correct
15 Correct 7 ms 33372 KB Output is correct
16 Correct 7 ms 33376 KB Output is correct
17 Correct 7 ms 33372 KB Output is correct
18 Correct 6 ms 33372 KB Output is correct
19 Correct 7 ms 33372 KB Output is correct
20 Correct 7 ms 33372 KB Output is correct
21 Correct 7 ms 33372 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 7 ms 33372 KB Output is correct
24 Correct 7 ms 33372 KB Output is correct
25 Correct 7 ms 33372 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
27 Correct 12 ms 34652 KB Output is correct
28 Correct 13 ms 34688 KB Output is correct
29 Correct 12 ms 34652 KB Output is correct
30 Correct 12 ms 34536 KB Output is correct
31 Correct 13 ms 34652 KB Output is correct
32 Correct 12 ms 34624 KB Output is correct
33 Correct 13 ms 34708 KB Output is correct
34 Correct 13 ms 34532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33372 KB Output is correct
2 Correct 7 ms 33380 KB Output is correct
3 Correct 7 ms 33372 KB Output is correct
4 Correct 7 ms 33372 KB Output is correct
5 Correct 7 ms 33368 KB Output is correct
6 Correct 7 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 7 ms 33368 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 7 ms 33456 KB Output is correct
12 Correct 7 ms 33372 KB Output is correct
13 Correct 7 ms 33396 KB Output is correct
14 Correct 7 ms 33372 KB Output is correct
15 Correct 7 ms 33372 KB Output is correct
16 Correct 7 ms 33376 KB Output is correct
17 Correct 7 ms 33372 KB Output is correct
18 Correct 6 ms 33372 KB Output is correct
19 Correct 7 ms 33372 KB Output is correct
20 Correct 7 ms 33372 KB Output is correct
21 Correct 7 ms 33372 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 7 ms 33372 KB Output is correct
24 Correct 7 ms 33372 KB Output is correct
25 Correct 7 ms 33372 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
27 Correct 12 ms 34652 KB Output is correct
28 Correct 13 ms 34688 KB Output is correct
29 Correct 12 ms 34652 KB Output is correct
30 Correct 12 ms 34536 KB Output is correct
31 Correct 13 ms 34652 KB Output is correct
32 Correct 12 ms 34624 KB Output is correct
33 Correct 13 ms 34708 KB Output is correct
34 Correct 13 ms 34532 KB Output is correct
35 Correct 43 ms 34396 KB Output is correct
36 Correct 42 ms 34392 KB Output is correct
37 Correct 43 ms 34556 KB Output is correct
38 Correct 46 ms 34392 KB Output is correct
39 Correct 42 ms 34396 KB Output is correct
40 Correct 28 ms 34648 KB Output is correct
41 Correct 30 ms 34652 KB Output is correct
42 Correct 30 ms 34684 KB Output is correct
43 Correct 24 ms 34652 KB Output is correct
44 Correct 30 ms 34652 KB Output is correct
45 Correct 28 ms 34652 KB Output is correct
46 Correct 24 ms 34652 KB Output is correct
47 Correct 23 ms 34652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33372 KB Output is correct
2 Correct 7 ms 33380 KB Output is correct
3 Correct 7 ms 33372 KB Output is correct
4 Correct 7 ms 33372 KB Output is correct
5 Correct 7 ms 33368 KB Output is correct
6 Correct 7 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 7 ms 33368 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 7 ms 33456 KB Output is correct
12 Correct 7 ms 33372 KB Output is correct
13 Correct 7 ms 33396 KB Output is correct
14 Correct 7 ms 33372 KB Output is correct
15 Correct 7 ms 33372 KB Output is correct
16 Correct 7 ms 33376 KB Output is correct
17 Correct 7 ms 33372 KB Output is correct
18 Correct 6 ms 33372 KB Output is correct
19 Correct 7 ms 33372 KB Output is correct
20 Correct 7 ms 33372 KB Output is correct
21 Correct 7 ms 33372 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 7 ms 33372 KB Output is correct
24 Correct 7 ms 33372 KB Output is correct
25 Correct 7 ms 33372 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
27 Correct 12 ms 34652 KB Output is correct
28 Correct 13 ms 34688 KB Output is correct
29 Correct 12 ms 34652 KB Output is correct
30 Correct 12 ms 34536 KB Output is correct
31 Correct 13 ms 34652 KB Output is correct
32 Correct 12 ms 34624 KB Output is correct
33 Correct 13 ms 34708 KB Output is correct
34 Correct 13 ms 34532 KB Output is correct
35 Correct 43 ms 34396 KB Output is correct
36 Correct 42 ms 34392 KB Output is correct
37 Correct 43 ms 34556 KB Output is correct
38 Correct 46 ms 34392 KB Output is correct
39 Correct 42 ms 34396 KB Output is correct
40 Correct 28 ms 34648 KB Output is correct
41 Correct 30 ms 34652 KB Output is correct
42 Correct 30 ms 34684 KB Output is correct
43 Correct 24 ms 34652 KB Output is correct
44 Correct 30 ms 34652 KB Output is correct
45 Correct 28 ms 34652 KB Output is correct
46 Correct 24 ms 34652 KB Output is correct
47 Correct 23 ms 34652 KB Output is correct
48 Correct 543 ms 52560 KB Output is correct
49 Correct 514 ms 52412 KB Output is correct
50 Correct 515 ms 52616 KB Output is correct
51 Correct 429 ms 52596 KB Output is correct
52 Correct 335 ms 50004 KB Output is correct
53 Correct 317 ms 50984 KB Output is correct
54 Correct 245 ms 48756 KB Output is correct
55 Correct 235 ms 48468 KB Output is correct
56 Correct 219 ms 48020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33372 KB Output is correct
2 Correct 7 ms 33380 KB Output is correct
3 Correct 7 ms 33372 KB Output is correct
4 Correct 7 ms 33372 KB Output is correct
5 Correct 7 ms 33368 KB Output is correct
6 Correct 7 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 7 ms 33368 KB Output is correct
10 Correct 7 ms 33372 KB Output is correct
11 Correct 7 ms 33456 KB Output is correct
12 Correct 7 ms 33372 KB Output is correct
13 Correct 7 ms 33396 KB Output is correct
14 Correct 7 ms 33372 KB Output is correct
15 Correct 7 ms 33372 KB Output is correct
16 Correct 7 ms 33376 KB Output is correct
17 Correct 7 ms 33372 KB Output is correct
18 Correct 6 ms 33372 KB Output is correct
19 Correct 7 ms 33372 KB Output is correct
20 Correct 7 ms 33372 KB Output is correct
21 Correct 7 ms 33372 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 7 ms 33372 KB Output is correct
24 Correct 7 ms 33372 KB Output is correct
25 Correct 7 ms 33372 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
27 Correct 12 ms 34652 KB Output is correct
28 Correct 13 ms 34688 KB Output is correct
29 Correct 12 ms 34652 KB Output is correct
30 Correct 12 ms 34536 KB Output is correct
31 Correct 13 ms 34652 KB Output is correct
32 Correct 12 ms 34624 KB Output is correct
33 Correct 13 ms 34708 KB Output is correct
34 Correct 13 ms 34532 KB Output is correct
35 Correct 43 ms 34396 KB Output is correct
36 Correct 42 ms 34392 KB Output is correct
37 Correct 43 ms 34556 KB Output is correct
38 Correct 46 ms 34392 KB Output is correct
39 Correct 42 ms 34396 KB Output is correct
40 Correct 28 ms 34648 KB Output is correct
41 Correct 30 ms 34652 KB Output is correct
42 Correct 30 ms 34684 KB Output is correct
43 Correct 24 ms 34652 KB Output is correct
44 Correct 30 ms 34652 KB Output is correct
45 Correct 28 ms 34652 KB Output is correct
46 Correct 24 ms 34652 KB Output is correct
47 Correct 23 ms 34652 KB Output is correct
48 Correct 543 ms 52560 KB Output is correct
49 Correct 514 ms 52412 KB Output is correct
50 Correct 515 ms 52616 KB Output is correct
51 Correct 429 ms 52596 KB Output is correct
52 Correct 335 ms 50004 KB Output is correct
53 Correct 317 ms 50984 KB Output is correct
54 Correct 245 ms 48756 KB Output is correct
55 Correct 235 ms 48468 KB Output is correct
56 Correct 219 ms 48020 KB Output is correct
57 Execution timed out 2557 ms 105304 KB Time limit exceeded
58 Halted 0 ms 0 KB -