답안 #496521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496521 2021-12-21T12:00:32 Z ergagan Meteors (POI11_met) C++17
100 / 100
4903 ms 65536 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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef int ll;
typedef long long i64;

//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) 3e5 + 17;
const ll M = (ll) 5e3 + 69;
const ll inf = (i64) 1e14 + 3;
const ll mod = (ll) 1e9 + 7;
ll sq(ll x) { return x * x; }

ll zxc = 1, n, m, q, a[N];
i64 t[4 * N];
ll l[N], r[N], x[N], lw[N], hg[N];

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

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

void upd(ll v, ll tl, ll tr, ll ql, ll qr, ll val) {
    if (tr < ql || qr < tl) return;
    if (ql <= tl && tr <= qr) { t[v] += val; return; }

    ll mid = (tl + tr) >> 1;
    upd(left(v), tl, mid, ql, qr, val);
    upd(right(v), mid + 1, tr, ql, qr, val);
}

void solve() {

    cin >> n >> m;

    for(ll i = 1; i <= m; i++) {
        ll val;
        cin >> val;
        v[val].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";
        memset(t, 0, sizeof(t));

        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++) {

            if(l[i] <= r[i])
                upd(1, 1, m, l[i], r[i], x[i]);

            else upd(1, 1, m, l[i], m, x[i]), upd(1, 1, m, 1, r[i], x[i]);

            for(ll id : vq[i]) {
                ok = 1;
                i64 sum = 0;
                for(ll x : v[id]) {
                    sum += get(1, 1, m, x, x);
                    if(sum >= a[id]) break;
                }
                if(sum >= a[id]) hg[id] = i;
                else lw[id] = i + 1;
            }

            vq[i].clear();
        }
    }

    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;
}
// さよならさ いかなくちゃ

Compilation message

met.cpp:15: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
   15 | #pragma comment(linker, "/stack:200000000")
      | 
met.cpp:29:27: warning: overflow in conversion from 'i64' {aka 'long long int'} to 'll' {aka 'int'} changes value from '100000000000003' to '276447235' [-Woverflow]
   29 | const ll inf = (i64) 1e14 + 3;
      |                ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23868 KB Output is correct
2 Correct 24 ms 23776 KB Output is correct
3 Correct 24 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23788 KB Output is correct
2 Correct 23 ms 23868 KB Output is correct
3 Correct 23 ms 23884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 302 ms 25156 KB Output is correct
2 Correct 441 ms 27076 KB Output is correct
3 Correct 430 ms 26752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 26164 KB Output is correct
2 Correct 421 ms 26220 KB Output is correct
3 Correct 406 ms 27256 KB Output is correct
4 Correct 106 ms 25632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 25588 KB Output is correct
2 Correct 269 ms 27664 KB Output is correct
3 Correct 169 ms 24416 KB Output is correct
4 Correct 421 ms 27144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 352 ms 24732 KB Output is correct
2 Correct 330 ms 26192 KB Output is correct
3 Correct 349 ms 24972 KB Output is correct
4 Correct 437 ms 28460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3933 ms 40880 KB Output is correct
2 Correct 1131 ms 28652 KB Output is correct
3 Correct 808 ms 26884 KB Output is correct
4 Correct 4903 ms 60376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4166 ms 39516 KB Output is correct
2 Correct 920 ms 28680 KB Output is correct
3 Correct 665 ms 26152 KB Output is correct
4 Correct 4567 ms 65536 KB Output is correct