Submission #217828

# Submission time Handle Problem Language Result Execution time Memory
217828 2020-03-30T23:34:26 Z Hideo Constellation 3 (JOI20_constellation3) C++11
0 / 100
12 ms 11392 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

struct point{
    int x, y, c;
} b[2 * N];

ll dp[N], g[4 * N];
int t[4 * N];
int a[N], next[N];
int n, m;

bool comp (point a, point b){
    if (a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}

void build (int v, int l, int r){
    if (l == r)
        t[v] = a[l];
    else {
        int mid = (l + r) >> 1;
        build(v + v, l, mid);
        build(v + v + 1, mid + 1, r);
        t[v] = max(t[v + v], t[v + v + 1]);
    }
}

int get (int v, int l, int r, int ql, int qr){
    if (ql <= l && r <= qr)
        return t[v];
    if (r < ql || qr < l)
        return 0;
    int mid = (l + r) >> 1;
    return max(get(v + v, l, mid, ql, qr), get(v + v + 1, mid + 1, r, ql, qr));
}

void upd (int v, int l, int r, int pos, ll val){
    if (l == r)
        g[v] = val;
    else {
        int mid = (l + r) >> 1;
        if (pos <= mid)
            upd(v + v, l, mid, pos, val);
        else
            upd(v + v + 1, mid + 1, r, pos, val);
        g[v] = g[v + v] + g[v + v + 1];
    }
}

ll get2 (int v, int l, int r, int ql, int qr){
    if (ql <= l && r <= qr)
        return g[v];
    if (r < ql || qr < l)
        return 0LL;
    int mid = (l + r) >> 1;
    return get2(v + v, l, mid, ql, qr) + get2(v + v + 1, mid + 1, r, ql, qr);
}

vi event[N];
vector < ll > cost[N];

main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        b[i] = {i, 0, 0};
    }
    cin >> m;
    m += n;
    a[++n] = INF;
    build(1, 1, n);
    for (int i = n; i <= m; i++)
        scanf("%d%d%d", &b[i].x, &b[i].y, &b[i].c);
    sort(b + 1, b + m + 1, comp);
    int l = 1;
    ll s = 0;
    for (int i = 1; i <= m; i++){
        s += b[i].c;
        if (b[i].x != b[i + 1].x){
            for (l; l <= i; l++){
                ll tmp;
                if (cost[b[l].x].size())
                    tmp = cost[b[l].x].back();
                else
                    tmp = INF;
                cost[b[l].x].pb(min(s - b[l].c, tmp));
                if (!b[l].y){
                    event[1].pb(b[l].x);
                    continue;
                }
                int ml = b[l].x, mr = n;
                while (ml + 1 < mr){
                    int mid = (ml + mr) >> 1;
                    if (get(1, 1, n, b[l].x, mid) >= b[l].y)
                        mr = mid;
                    else
                        ml = mid;
                }
                event[mr].pb(b[l].x);
            }
            l = i + 1;
            s = 0;
        }
    }
    a[0] = INF;
    int cur = 1;
    memset(dp, 0x3f3f3f3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 1; i < n; i++){
        for (int it : event[i]){
            upd(1, 1, m, it, cost[it][next[it]]);
            next[it]++;
        }
        int cnt = 0;
        for (cur; cur <= m && b[cur].x == i; cur++){
            int l = 0, r = i;
            while (l + 1 < r){
                int mid = (l + r) >> 1;
                if (get(1, 1, n, mid, i) >= b[cur].y)
                    l = mid;
                else
                    r = mid;
            }
            ll res = dp[l] + cost[i][cnt];
            if (l + 1 <= i - 1)
                res += get2(1, 1, m, l + 1, i - 1);
            dp[i] = min(dp[i], res);
            cnt++;
        }
    }
    cout << dp[n - 1];
}


Compilation message

constellation3.cpp:83:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
constellation3.cpp: In function 'int main()':
constellation3.cpp:101:19: warning: statement has no effect [-Wunused-value]
             for (l; l <= i; l++){
                   ^
constellation3.cpp:136:17: warning: statement has no effect [-Wunused-value]
         for (cur; cur <= m && b[cur].x == i; cur++){
                 ^
constellation3.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
constellation3.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &b[i].x, &b[i].y, &b[i].c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 11392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 11392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 11392 KB Output isn't correct
2 Halted 0 ms 0 KB -