답안 #496351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496351 2021-12-21T06:15:03 Z ergagan Meteors (POI11_met) C++17
24 / 100
6000 ms 65540 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, n, m, q, a[N];
ll l[N], r[N], x[N];
ll p[N], cur[N], lw[N], hg[N];

vector<ll> v[N], vq[N];

void upd(ll l, ll r, ll x, ll i) {
    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;
        }
    }
}

void solve() {

    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;

    for(ll i = 1; i <= n; i++)
        lw[i] = 1, hg[i] = q + 1;

    for(ll i = 1; i <= q; i++) {
        cin >> l[i] >> r[i] >> x[i];
    }

    ll ok = 1;
    while(ok) {
        ok = 0;
//        cout << "OK\n";

        for(ll i = 1; i <= n; i++) cur[i] = 0;

        for(ll i = 1; i <= n; i++) {
            if(lw[i] != hg[i])
                vq[(lw[i] + hg[i]) / 2].pb(i);
        }

        for(ll i = 1; i <= q; i++) {
            upd(l[i], r[i], x[i], i);

            while(!vq[i].empty()) {
                ok = 1;

                ll id = vq[i].back();
                vq[i].pop_back();

                if(cur[id] >= a[id]) hg[id] = i;
                else lw[id] = i + 1;
            }
        }
    }

    for(ll i = 1; i <= n; i++) {
        cout << (lw[i] <= q ? to_string(lw[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 60 ms 47308 KB Output is correct
2 Correct 91 ms 47412 KB Output is correct
3 Correct 85 ms 47396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 47336 KB Output is correct
2 Correct 97 ms 47568 KB Output is correct
3 Correct 90 ms 47420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6091 ms 49888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6048 ms 49944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6051 ms 49844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6070 ms 49680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 141 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 141 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -