Submission #57454

# Submission time Handle Problem Language Result Execution time Memory
57454 2018-07-15T05:33:30 Z 강태규(#1669) Teams (CEOI11_tea) C++11
30 / 100
1107 ms 65340 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int inf = 1e7;
int n;
pii a[1000001];
int pr[1000001];

struct node {
    int cnt, mx, i;
    node() {}
    node(int cnt, int mx, int i) : cnt(cnt), mx(mx), i(i) {}
    
    node operator+=(const node &p) {
        cnt += p.cnt;
        mx = max(mx, p.mx);
        i = p.i;
    }
    
    bool operator<(const node &p) const {
        if (cnt != p.cnt) return cnt < p.cnt;
        if (mx != p.mx) return mx > p.mx;
        return i < p.i;
    }
} seg[1 << 21], dp[1000001];

void update(int i, int s, int e, int x, node v) {
    if (s == e) {
        seg[i] = v;
        return;
    }
    int m = (s + e) / 2;
    if (x <= m) update(i << 1, s, m, x, v);
    else update(i << 1 | 1, m + 1, e, x, v);
    seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}

node query(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return node(-inf, inf, -inf);
    if (x <= s && e <= y) return seg[i];
    int m = (s + e) / 2;
    return max(query(i << 1, s, m, x, y), query(i << 1 | 1, m + 1, e, x, y));
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int x;
        scanf("%d", &x);
        a[i] = pii(x, i);
    }
    sort(a + 1, a + (n + 1));
    update(1, 0, n, 0, node(0, a[n - 1].first, 0));
    for (int i = 1; i <= n; ++i) {
        int x = i - a[i].first;
        dp[i] = query(1, 0, n, 0, x);
        pr[i] = dp[i].i;
        dp[i] += node(1, i - pr[i], i);
        update(1, 0, n, i, dp[i]);
    }
    vector<pii> ans;
    for (int i = n; i > 0; i = pr[i]) {
        ans.emplace_back(pr[i], i);
    }
    printf("%d\n", (int)ans.size());
    for (pii i : ans) {
        printf("%d", i.second - i.first);
        for (int j = i.first + 1; j <= i.second; ++j) {
            printf(" %d", a[j].second);
        }
        printf("\n");
    }
	return 0;
}

Compilation message

tea.cpp: In member function 'node node::operator+=(const node&)':
tea.cpp:35:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
tea.cpp: In function 'int main()':
tea.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
tea.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 3 ms 472 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 824 KB Output is correct
2 Incorrect 6 ms 840 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 5980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 6244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 656 ms 47896 KB Output is correct
2 Correct 813 ms 48188 KB Output is correct
3 Correct 728 ms 48188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1107 ms 55572 KB Output is correct
2 Correct 1012 ms 65340 KB Output is correct
3 Correct 942 ms 65340 KB Output is correct
4 Correct 988 ms 65340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 894 ms 65340 KB Output isn't correct
2 Halted 0 ms 0 KB -