Submission #556721

# Submission time Handle Problem Language Result Execution time Memory
556721 2022-05-03T18:41:27 Z new_acc Volontiranje (COCI21_volontiranje) C++14
110 / 110
604 ms 295912 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<20;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int t[N],num[N],seg2[(SS<<1)+10],dp[N];
vi seg[N],pom[N],c;
bool dg=0;
void upd(int a,int b){
    for(a+=SS;a>0;a>>=1) seg2[a]=max(seg2[a],b);
}
int Query(int a,int b){
    int res=0;
    for(a+=SS-1,b+=SS+1;(a>>1)!=(b>>1);a>>=1,b>>=1){
        if(!(a&1)) res=max(res,seg2[a+1]);
        if(b&1) res=max(res,seg2[b-1]);
    }
    return res;
}
void upd2(int x,int a,int b){
    a+=num[x],seg[x][a]=b;
    for(a>>=1;a>0;a>>=1) seg[x][a]=min(seg[x][(a<<1)],seg[x][(a<<1)+1]);
}
int Query2(int curr,int x,int v=1){
    if(v>num[curr]) return v-num[curr];
    if(seg[curr][(v<<1)+1]<=x) return Query2(curr,x,(v<<1)+1);
    else return Query2(curr,x,(v<<1));
}
int rek(int curr,int ind){
    if(curr==0) return 1;
    int q=Query2(curr,ind);
    while(seg[curr][1]<ind and t[ind]>t[pom[curr][q-1]] and rek(curr-1,pom[curr][q-1])==-1){
        upd2(curr,q,INFi);
        q=Query2(curr,ind);
    } 
    if(seg[curr][1]>ind or t[ind]<t[pom[curr][q-1]]) return -1;
    c.push_back(pom[curr][q-1]);
    upd2(curr,q,INFi);
    return 1;
}
void solve(){
    int n,maxi=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t[i];
        dp[i]=Query(1,t[i])+1;
        upd(t[i],dp[i]);
        pom[dp[i]].push_back(i);
        maxi=max(maxi,dp[i]);
    }
    t[n+1]=n+1;
    for(int i=1;i<=maxi;i++){
        int curr=1;
        while(curr<=pom[i].size()) curr<<=1;
        for(int k=1;k<=(curr<<1)+5;k++) seg[i].push_back(INFi);
        num[i]=curr;
        for(int j=0;j<pom[i].size();j++) upd2(i,j+1,pom[i][j]);
    }
    vector<vi>ans;
    while(rek(maxi,n+1)>0) ans.push_back(c),c.clear();
    cout<<ans.size()<<" "<<maxi<<"\n";
    for(auto u:ans){
        for(auto xd:u) cout<<xd<<" ";
        cout<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int tt=1;
    while(tt--) solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         while(curr<=pom[i].size()) curr<<=1;
      |               ~~~~^~~~~~~~~~~~~~~
Main.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j=0;j<pom[i].size();j++) upd2(i,j+1,pom[i][j]);
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47316 KB Output is correct
2 Correct 25 ms 47324 KB Output is correct
3 Correct 27 ms 47320 KB Output is correct
4 Correct 25 ms 47272 KB Output is correct
5 Correct 33 ms 47296 KB Output is correct
6 Correct 28 ms 47276 KB Output is correct
7 Correct 33 ms 47308 KB Output is correct
8 Correct 23 ms 47316 KB Output is correct
9 Correct 27 ms 47292 KB Output is correct
10 Correct 24 ms 47308 KB Output is correct
11 Correct 27 ms 47296 KB Output is correct
12 Correct 30 ms 47308 KB Output is correct
13 Correct 26 ms 47316 KB Output is correct
14 Correct 25 ms 47268 KB Output is correct
15 Correct 25 ms 47260 KB Output is correct
16 Correct 26 ms 47336 KB Output is correct
17 Correct 25 ms 47356 KB Output is correct
18 Correct 32 ms 47296 KB Output is correct
19 Correct 29 ms 47316 KB Output is correct
20 Correct 32 ms 47348 KB Output is correct
21 Correct 27 ms 47316 KB Output is correct
22 Correct 26 ms 47312 KB Output is correct
23 Correct 24 ms 47292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47316 KB Output is correct
2 Correct 25 ms 47324 KB Output is correct
3 Correct 27 ms 47320 KB Output is correct
4 Correct 25 ms 47272 KB Output is correct
5 Correct 33 ms 47296 KB Output is correct
6 Correct 28 ms 47276 KB Output is correct
7 Correct 33 ms 47308 KB Output is correct
8 Correct 23 ms 47316 KB Output is correct
9 Correct 27 ms 47292 KB Output is correct
10 Correct 24 ms 47308 KB Output is correct
11 Correct 27 ms 47296 KB Output is correct
12 Correct 30 ms 47308 KB Output is correct
13 Correct 26 ms 47316 KB Output is correct
14 Correct 25 ms 47268 KB Output is correct
15 Correct 25 ms 47260 KB Output is correct
16 Correct 26 ms 47336 KB Output is correct
17 Correct 25 ms 47356 KB Output is correct
18 Correct 32 ms 47296 KB Output is correct
19 Correct 29 ms 47316 KB Output is correct
20 Correct 32 ms 47348 KB Output is correct
21 Correct 27 ms 47316 KB Output is correct
22 Correct 26 ms 47312 KB Output is correct
23 Correct 24 ms 47292 KB Output is correct
24 Correct 24 ms 47308 KB Output is correct
25 Correct 45 ms 47272 KB Output is correct
26 Correct 25 ms 47364 KB Output is correct
27 Correct 26 ms 47344 KB Output is correct
28 Correct 27 ms 47392 KB Output is correct
29 Correct 30 ms 47564 KB Output is correct
30 Correct 26 ms 47360 KB Output is correct
31 Correct 26 ms 47384 KB Output is correct
32 Correct 25 ms 47336 KB Output is correct
33 Correct 26 ms 47444 KB Output is correct
34 Correct 26 ms 47368 KB Output is correct
35 Correct 26 ms 47420 KB Output is correct
36 Correct 26 ms 47372 KB Output is correct
37 Correct 31 ms 47316 KB Output is correct
38 Correct 32 ms 47400 KB Output is correct
39 Correct 26 ms 47376 KB Output is correct
40 Correct 25 ms 47352 KB Output is correct
41 Correct 27 ms 47356 KB Output is correct
42 Correct 25 ms 47336 KB Output is correct
43 Correct 28 ms 47272 KB Output is correct
44 Correct 25 ms 47348 KB Output is correct
45 Correct 26 ms 47320 KB Output is correct
46 Correct 26 ms 47316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47316 KB Output is correct
2 Correct 25 ms 47324 KB Output is correct
3 Correct 27 ms 47320 KB Output is correct
4 Correct 25 ms 47272 KB Output is correct
5 Correct 33 ms 47296 KB Output is correct
6 Correct 28 ms 47276 KB Output is correct
7 Correct 33 ms 47308 KB Output is correct
8 Correct 23 ms 47316 KB Output is correct
9 Correct 27 ms 47292 KB Output is correct
10 Correct 24 ms 47308 KB Output is correct
11 Correct 27 ms 47296 KB Output is correct
12 Correct 30 ms 47308 KB Output is correct
13 Correct 26 ms 47316 KB Output is correct
14 Correct 25 ms 47268 KB Output is correct
15 Correct 25 ms 47260 KB Output is correct
16 Correct 26 ms 47336 KB Output is correct
17 Correct 25 ms 47356 KB Output is correct
18 Correct 32 ms 47296 KB Output is correct
19 Correct 29 ms 47316 KB Output is correct
20 Correct 32 ms 47348 KB Output is correct
21 Correct 27 ms 47316 KB Output is correct
22 Correct 26 ms 47312 KB Output is correct
23 Correct 24 ms 47292 KB Output is correct
24 Correct 24 ms 47308 KB Output is correct
25 Correct 45 ms 47272 KB Output is correct
26 Correct 25 ms 47364 KB Output is correct
27 Correct 26 ms 47344 KB Output is correct
28 Correct 27 ms 47392 KB Output is correct
29 Correct 30 ms 47564 KB Output is correct
30 Correct 26 ms 47360 KB Output is correct
31 Correct 26 ms 47384 KB Output is correct
32 Correct 25 ms 47336 KB Output is correct
33 Correct 26 ms 47444 KB Output is correct
34 Correct 26 ms 47368 KB Output is correct
35 Correct 26 ms 47420 KB Output is correct
36 Correct 26 ms 47372 KB Output is correct
37 Correct 31 ms 47316 KB Output is correct
38 Correct 32 ms 47400 KB Output is correct
39 Correct 26 ms 47376 KB Output is correct
40 Correct 25 ms 47352 KB Output is correct
41 Correct 27 ms 47356 KB Output is correct
42 Correct 25 ms 47336 KB Output is correct
43 Correct 28 ms 47272 KB Output is correct
44 Correct 25 ms 47348 KB Output is correct
45 Correct 26 ms 47320 KB Output is correct
46 Correct 26 ms 47316 KB Output is correct
47 Correct 137 ms 64632 KB Output is correct
48 Correct 162 ms 65440 KB Output is correct
49 Correct 185 ms 71008 KB Output is correct
50 Correct 378 ms 87232 KB Output is correct
51 Correct 86 ms 58936 KB Output is correct
52 Correct 581 ms 295912 KB Output is correct
53 Correct 604 ms 144608 KB Output is correct
54 Correct 594 ms 96740 KB Output is correct
55 Correct 502 ms 96788 KB Output is correct
56 Correct 27 ms 47828 KB Output is correct
57 Correct 273 ms 85028 KB Output is correct
58 Correct 70 ms 56908 KB Output is correct
59 Correct 66 ms 55504 KB Output is correct
60 Correct 321 ms 85472 KB Output is correct
61 Correct 176 ms 72616 KB Output is correct
62 Correct 28 ms 47308 KB Output is correct
63 Correct 26 ms 47316 KB Output is correct
64 Correct 26 ms 47292 KB Output is correct
65 Correct 25 ms 47288 KB Output is correct
66 Correct 24 ms 47272 KB Output is correct
67 Correct 25 ms 47280 KB Output is correct
68 Correct 26 ms 47276 KB Output is correct
69 Correct 24 ms 47280 KB Output is correct