답안 #496283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496283 2021-12-21T04:53:34 Z ergagan Meteors (POI11_met) C++17
24 / 100
6000 ms 33732 KB
//я так много думал, что опять попал
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define f first
#define s second
#define left(v) v + v
#define right(v) v + v + 1
#define ub upper_bound
#define lb lower_bound

using namespace std;
typedef long long ll;

//17 SEVENTEEN
const long double Pi = acos(-1.0);
const ll dx[] = {0,0,1,-1};
const ll dy[] = {1,-1,0,0};
const ll N = (ll) 1e6 + 17;
const ll M = (ll) 5e3 + 69;
const ll inf = (ll) 1e14 + 3;
const ll mod = (ll) 1e9 + 7;
ll sq(ll x) { return x * x; }

ll zxc = 1, a[N], t[4 * N], uv[4 * N];
ll l, r, i, x;
ll p[N], ans[N], cur[N];

vector<ll> v[N];

void recalc(ll v) {
    t[v] = t[left(v)] + t[right(v)];
}

void push(ll v, ll tl, ll tr) {
    if (!uv[v]) return;
    if (tl < tr) {
        uv[left(v)] += uv[v];
        uv[right(v)] += uv[v];
    }
    t[v] += uv[v] * 1ll * (tr - tl + 1);
    uv[v] = 0;
}

ll get(ll v, ll tl, ll tr, ll l, ll r) {
    push(v, tl, tr);
    if(l <= tl && tr <= r) return t[v];
    if(tr < l || r < tl) return 0;
    ll tm = (tl + tr) / 2;
    return get(left(v), tl, tm, l, r) + get(right(v), tm + 1, tr, l, r);
}

void upd(ll v, ll tl, ll tr, ll ql, ll qr, ll val) {
    push(v, tl, tr);
    if (tr < ql || qr < tl) return;
    if (ql <= tl && tr <= qr) {
        uv[v] += val;
        push(v, tl, tr);
        return;
    }
    ll mid = (tl + tr) / 2;
    upd(left(v), tl, mid, ql, qr, val);
    upd(right(v), mid + 1, tr, ql, qr, val);
    recalc(v);
}

void solve() {
    ll n, m, q;
    cin >> n >> m;
    for(ll i = 1; i <= m; i++) {
        cin >> p[i];
        v[p[i]].pb(i);
    }
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    cin >> q;

    fill(ans + 1, ans + n + 1, -1);
    for(ll time = 0; time < q; time++) {

        for(ll i = 1; i <= n; i++) {
            if(cur[i] >= a[i] && !(~ans[i])) ans[i] = time;
//            cout << cur[i] << " ";
        }
//        cout << "\n";

        cin >> l >> r >> x;

        if(l <= r) {
            for(ll i = 1; i <= n; i++) {
                ll lf = lb(all(v[i]), l) - v[i].begin();
                ll rg = ub(all(v[i]), r) - v[i].begin();
                if(rg - lf > 0) cur[i] += (rg - lf) * x;
            }
        }
        else {
            for(ll i = 1; i <= n; i++) {
                ll len = 0;
                len += (v[i].size() - 1) - (lb(all(v[i]), l) - v[i].begin()) + 1;
                len += ub(all(v[i]), r) - v[i].begin();
                if(len > 0) cur[i] += len * x;
            }
        }
    }
    for(ll i = 1; i <= n; i++) {
        if(cur[i] >= a[i] && !(~ans[i])) ans[i] = q;
//        cout << cur[i] << " ";
    }
//    cout << "\n";
    for(ll i = 1; i <= n; i++) {
        cout << (~ans[i] ? to_string(ans[i]) : "NIE") << "\n";
    }
}

int main(/*Уверенно*/) {
ios_base::sync_with_stdio(0);
    cin.tie(0);
/*
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
*/
//    cin >> zxc;
    while(zxc--) {
        solve();
    }
  	return 0;
}
// さよならさ いかなくちゃ
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 24 ms 23848 KB Output is correct
3 Correct 22 ms 23864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23872 KB Output is correct
2 Correct 20 ms 23876 KB Output is correct
3 Correct 19 ms 23820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1608 ms 24884 KB Output is correct
2 Execution timed out 6074 ms 25548 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6091 ms 25036 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2877 ms 24996 KB Output is correct
2 Execution timed out 6063 ms 25564 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1330 ms 24728 KB Output is correct
2 Execution timed out 6093 ms 25032 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6060 ms 33732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6062 ms 33240 KB Time limit exceeded
2 Halted 0 ms 0 KB -