# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
264327 |
2020-08-14T06:12:55 Z |
임성재(#5088) |
Teams (CEOI11_tea) |
C++17 |
|
914 ms |
93848 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;
vector<int> q;
for(int i=1; i<=n; i++) {
int s;
cin >> s;
v.eb(s, i);
q.eb(i);
}
v.eb(-inf, 0);
sort(all(v));
init(1, 0, n);
update(1, 0, n, 0, 0);
sort(all(q), [](int i, int j) {
return i - v[i].fi < j - v[j].fi;
});
int j = 1;
for(auto i : q) {
dp[i] = -inf;
if(i - v[i].fi < 0) 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:115:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | while(idx < ans.size() && ans[idx][0] >= i) {
| ~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
672 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
4076 KB |
Output is correct |
2 |
Correct |
43 ms |
4080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
4460 KB |
Output is correct |
2 |
Correct |
52 ms |
4076 KB |
Output is correct |
3 |
Correct |
63 ms |
4340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
484 ms |
33208 KB |
Output is correct |
2 |
Correct |
452 ms |
33660 KB |
Output is correct |
3 |
Correct |
445 ms |
33876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
597 ms |
41472 KB |
Output is correct |
2 |
Correct |
914 ms |
93848 KB |
Output is correct |
3 |
Correct |
579 ms |
40800 KB |
Output is correct |
4 |
Correct |
538 ms |
36824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
530 ms |
44372 KB |
Output is correct |
2 |
Correct |
432 ms |
40276 KB |
Output is correct |
3 |
Correct |
581 ms |
40148 KB |
Output is correct |
4 |
Correct |
671 ms |
40724 KB |
Output is correct |