#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
using namespace std;
///~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename H, typename T>
ostream& operator<<(ostream& os, pair<H, T> m){
return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H>
ostream& operator<<(ostream& os, vector<H> V){
os<<"{";
for(int i=0; i<V.size(); i++){
if(i)os<<" ";
os<<V[i];
}
os<<"}";
return os;
}
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
///~~~~~~~~~~~~~~~~~~~~~~~~~
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=2e5+5, INF=1e9+5, mod=1e9+7;
vi id[N], mini[N];//id-kto ma dp o takiej wartosci, mini-najmniejsza najwieksza druzyna
int dp[N], gdzie[N], par[N], opt[N];//dp-ile druz, gdzie-numer w wektorze, par-rodzic, opt-maxi na przedziale
int main(){
//BOOST;
int n;
cin>>n;
vii V(n+1);
for(int i=1; i<=n; i++){
cin>>V[i].st;
V[i].nd=i;
}
sor(V);
id[0].pb(0);
mini[0].pb(0);
for(int i=1; i<=n; i++){
//deb(i);
int j=i-V[i].st;
if(j<0){
dp[i]=N;
opt[i]=opt[i-1];
}
else{
//deb(i);
int k=dp[opt[j]];
dp[i]=k+1;
//gdzie[i]=id[k+1].size();
//id[k+1].pb(i);
opt[i]=max(opt[i-1], k+1);
int l=0, r=id[k].size();
//deb(i);
while(l<r){
int m=(l+r)>>1;
if(i-m>mini[k][m])l=m+1;
else r=m;
}
//deb(i);
int m;
if(l==id[k].size() || (l!=0 && i-l+1>mini[k][l])){
par[i]=id[k][l-1];
m=i-l+1;
}
else{
par[i]=id[k][l];
m=mini[k][l];
}
//deb(i);
while(id[k+1].size() && m<=mini[k+1].back()){
id[k+1].pp();
mini[k+1].pp();
}
id[k+1].pb(i);
mini[k+1].pb(m);
//deb(i);
}
}
cout<<dp[n]<<"\n";
int v=n;
while(v!=0){
int v2=par[v];
cout<<v-v2<<" ";
for(int i=v; i>v2; i--){
cout<<V[i].nd<<" ";
}
cout<<"\n";
v=v2;
}
}
Compilation message
tea.cpp: In function 'int main()':
tea.cpp:96:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | if(l==id[k].size() || (l!=0 && i-l+1>mini[k][l])){
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Runtime error |
13 ms |
19488 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
15 ms |
19540 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
13 ms |
19436 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
19568 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
15 ms |
19660 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
41 ms |
21432 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
47 ms |
22204 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
253 ms |
35116 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
391 ms |
45756 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
417 ms |
46960 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |