# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
264232 |
2020-08-14T05:43:40 Z |
임성재(#5088) |
Teams (CEOI11_tea) |
C++17 |
|
564 ms |
40388 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define pre(a) cout << fixed; cout.precision(a);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n;
vector<pii> v;
int tree[4000010];
int dp[1000010];
int pre[1000010];
bool chk[1000010];
vector<vector<int>> ans;
priority_queue<pii, vector<pii>, greater<pii>> pQ;
void init(int node, int s, int e) {
tree[node] = -inf;
if(s == e) return;
init(node*2, s, (s+e)/2);
init(node*2+1, (s+e)/2+1, e);
}
void update(int node, int s, int e, int i, int x) {
if(s == e) {
tree[node] = x;
return;
}
int m = (s+e)/2;
if(i <= m) update(node*2, s, m, i, x);
else update(node*2+1, m+1, e, i, x);
tree[node] = max(tree[node*2], tree[node*2+1]);
}
int Find(int node, int s, int e) {
if(s == e) return s;
if(tree[node*2] > tree[node*2+1]) return Find(node*2, s, (s+e)/2);
else return Find(node*2+1, (s+e)/2+1, e);
}
int main() {
fast;
cin >> n;
for(int i=1; i<=n; i++) {
int s;
cin >> s;
v.eb(s, i);
}
v.eb(-inf, 0);
sort(all(v));
init(1, 0, n);
update(1, 0, n, 0, 0);
int j = 1;
for(int i=1; i<=n; i++) {
dp[i] = -inf;
if(i < v[i].fi) continue;
while(j <= i - v[i].fi) {
update(1, 0, n, j, dp[j]);
j++;
}
int u = Find(1, 0, n);
pre[i] = u;
dp[i] = dp[u] + 1;
}
for(int i = n; i; i = pre[i]) {
vector<int> x;
for(int j = i; j > i - v[i].fi; j--) {
x.eb(j);
chk[j] = true;
}
ans.eb(x);
}
int idx = 0;
for(int i=n; i>0; i--) {
if(chk[i]) continue;
while(idx < ans.size() && ans[idx][0] > i) {
pQ.em(ans[idx].size(), idx);
idx++;
}
auto j = pQ.top();
pQ.pop();
ans[j.se].eb(i);
pQ.em(j.fi+1, j.se);
}
cout << ans.size() << "\n";
for(auto i : ans) {
cout << i.size() << " ";
for(auto j : i) {
cout << v[j].se << " ";
}
cout << "\n";
}
}
Compilation message
tea.cpp: In function 'int main()':
tea.cpp:109:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | while(idx < ans.size() && ans[idx][0] > i) {
| ~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
404 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
640 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
3824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
4080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
400 ms |
29688 KB |
Output is correct |
2 |
Correct |
403 ms |
30420 KB |
Output is correct |
3 |
Incorrect |
405 ms |
31828 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
542 ms |
37512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
444 ms |
40388 KB |
Output is correct |
2 |
Correct |
405 ms |
36184 KB |
Output is correct |
3 |
Correct |
536 ms |
36308 KB |
Output is correct |
4 |
Incorrect |
564 ms |
37516 KB |
Output isn't correct |