Submission #762452

# Submission time Handle Problem Language Result Execution time Memory
762452 2023-06-21T12:09:39 Z Chal1shkan Meteors (POI11_met) C++14
74 / 100
5329 ms 65536 KB
//Bismillahir-Rahmanir-Rahim
 
# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 3e5 + 25;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
const ll P = 67;
 
using namespace std;
 
int n, m, q, tl[maxn], tr[maxn];
vector <int> boss[maxn];
int need[maxn], ans[maxn];
int l[maxn], r[maxn];
ll a[maxn];
vector <int> check[maxn];
 
struct segtree
{
    ll t[maxn * 4];
    ll z[maxn * 4];
    void build (int v = 1, int tl = 1, int tr = m)
    {
        t[v] = z[v] = 0;
        if (tl == tr)
        {
            return;
        }   
        int tm = (tl + tr) >> 1;
        build (v * 2, tl, tm);
        build (v * 2 + 1, tm + 1, tr);
    }       
    void push (int v, int tl, int tr)
    {
        if (z[v] && tl != tr)
        {
            int tm = (tl + tr) >> 1;
            t[v * 2] += z[v] * 1LL * (tm - tl + 1);
            t[v * 2 + 1] += z[v] * 1LL * (tr - tm);
            z[v * 2] += z[v];
            z[v * 2 + 1] += z[v];
            z[v] = 0;
        }
    }
    void update (int l, int r, int x, int v = 1, int tl = 1, int tr = m)
    {
        push(v, tl, tr);
        if (tr < l || r < tl) return;
        if (l <= tl && tr <= r)
        {
            t[v] += x * 1LL * (tr - tl + 1);
            z[v] += x;
            return;
        }
        int tm = (tl + tr) >> 1;
        update(l, r, x, v * 2, tl, tm);
        update(l, r, x, v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }
    ll get (int pos, int v = 1, int tl = 1, int tr = m)
    {
        push(v, tl, tr);
        if (tl == tr)
        {
            return t[v];
        }
        int tm = (tl + tr) >> 1;
        if (pos <= tm)
            return get(pos, v * 2, tl, tm);
        else
            return get(pos, v * 2 + 1, tm + 1, tr);
    }
} t;
 
void ma1n (/* SABR */)
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        int owner;
        cin >> owner;
        boss[owner].pb(i);
    }
    for (int i = 1; i <= n; ++i)
    {
        cin >> need[i];
    }
    cin >> q;
    for (int i = 1; i <= q; ++i)
    {
        cin >> l[i] >> r[i] >> a[i];
    }
    for (int i = 1; i <= n; ++i)
    {
        tl[i] = 1, tr[i] = q, ans[i] = -1;
    }
    bool boo = 1;
    while (boo)
    {
        boo = 0;
        t.build();
        for (int i = 1; i <= n; ++i)
        {
            if (tl[i] <= tr[i])
            {
                check[(tl[i] + tr[i]) >> 1].pb(i);
            }
//          cout << tl[i] << ' ' << tr[i] << nl;
        }
        for (int i = 1; i <= q; ++i)
        {
            if (l[i] <= r[i])
            {
                t.update(l[i], r[i], a[i]);
            }
            else
            {
                t.update(l[i], m, a[i]);
                t.update(1, r[i], a[i]);
            }
            while (!check[i].empty())
            {
                boo = 1;
                int id = check[i].back();
                check[i].pop_back();
                ll sum = 0;
                for (int x : boss[id])
                {
                    sum += t.get(x);
                    if (sum >= need[id]) break;
                }
                if (sum >= need[id])
                {
                    tr[id] = i - 1;
                    ans[id] = i;
                }
                else
                {
                    tl[id] = i + 1;
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        if (ans[i] == -1)
        {
            cout << "NIE" << nl;
        }
        else
        {
            cout << ans[i] << nl;
        }
    }
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << '\n';
        ma1n();
    }
    return 0;
}
 
// 998batrr | BbIWEJI 3A TObOU!!!
// tourist  | BbIWEJI 3A TObOU!!!
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14420 KB Output is correct
2 Correct 11 ms 14516 KB Output is correct
3 Correct 11 ms 14532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 14536 KB Output is correct
2 Correct 13 ms 14548 KB Output is correct
3 Correct 11 ms 14548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 420 ms 18092 KB Output is correct
2 Correct 520 ms 20108 KB Output is correct
3 Correct 527 ms 19704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 478 ms 19080 KB Output is correct
2 Correct 485 ms 19124 KB Output is correct
3 Correct 518 ms 20200 KB Output is correct
4 Correct 85 ms 18432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 18496 KB Output is correct
2 Correct 328 ms 20760 KB Output is correct
3 Correct 242 ms 15284 KB Output is correct
4 Correct 490 ms 20148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 486 ms 17616 KB Output is correct
2 Correct 431 ms 19172 KB Output is correct
3 Correct 456 ms 17864 KB Output is correct
4 Correct 512 ms 21596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5074 ms 49500 KB Output is correct
2 Correct 2117 ms 36876 KB Output is correct
3 Correct 1257 ms 18536 KB Output is correct
4 Runtime error 5329 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5180 ms 48072 KB Output is correct
2 Correct 1307 ms 36872 KB Output is correct
3 Correct 1004 ms 17740 KB Output is correct
4 Runtime error 4317 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -