Submission #762445

# Submission time Handle Problem Language Result Execution time Memory
762445 2023-06-21T12:02:26 Z Chal1shkan Meteors (POI11_met) C++14
74 / 100
1066 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;
 
ll n, m, q, tl[maxn], tr[maxn];
vector <ll> boss[maxn];
ll need[maxn], ans[maxn];
ll l[maxn], r[maxn], a[maxn];
vector <ll> check[maxn];
 
struct fenwick
{
    ll t[maxn];
    void clear ()
    {
        for (ll i = 1; i <= m; ++i)
        {
            t[i] = 0;
        }
    }
    void update (ll id, ll x)
    {
        for (; id < maxn; id += (id & (-id)))
        {
            t[id] += x;
        }
    }
    ll get (ll id)
    {
        ll res = 0;
        for (; id >= 1; id -= (id & (-id)))
        {
            res += t[id];
        }
        return res;
    }
} t;
 
void ma1n (/* SABR */)
{
    cin >> n >> m;
    for (ll i = 1; i <= m; ++i)
    {
        ll owner;
        cin >> owner;
        boss[owner].pb(i);
    }
    for (ll i = 1; i <= n; ++i)
    {
        cin >> need[i];
    }
    cin >> q;
    for (ll i = 1; i <= q; ++i)
    {
        cin >> l[i] >> r[i] >> a[i];
    }
    for (ll i = 1; i <= n; ++i)
    {
        tl[i] = 1, tr[i] = q, ans[i] = -1;
    }
    bool boo = 1;
    while (boo)
    {
        boo = 0;
        t.clear();
        for (ll 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 (ll i = 1; i <= q; ++i)
        {
            if (l[i] <= r[i])
            {
                t.update(l[i], a[i]);
                t.update(r[i] + 1, -a[i]);
            }
            else
            {
                t.update(1, a[i]);
                t.update(r[i] + 1, -a[i]);
                t.update(l[i], a[i]);
            }
            while (!check[i].empty())
            {
                boo = 1;
                ll id = check[i].back();
                check[i].pop_back();
                ll sum = 0;
                for (ll 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 (ll 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 8 ms 14548 KB Output is correct
2 Correct 8 ms 14548 KB Output is correct
3 Correct 9 ms 14548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14568 KB Output is correct
2 Correct 8 ms 14548 KB Output is correct
3 Correct 8 ms 14676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 17996 KB Output is correct
2 Correct 148 ms 21588 KB Output is correct
3 Correct 97 ms 20320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 19588 KB Output is correct
2 Correct 117 ms 19504 KB Output is correct
3 Correct 140 ms 21940 KB Output is correct
4 Correct 38 ms 18408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 18528 KB Output is correct
2 Correct 204 ms 22128 KB Output is correct
3 Correct 112 ms 16076 KB Output is correct
4 Correct 95 ms 20932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 17124 KB Output is correct
2 Correct 126 ms 19420 KB Output is correct
3 Correct 82 ms 17584 KB Output is correct
4 Correct 134 ms 23112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 998 ms 49296 KB Output is correct
2 Correct 658 ms 27088 KB Output is correct
3 Correct 572 ms 20808 KB Output is correct
4 Runtime error 1066 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1022 ms 47328 KB Output is correct
2 Correct 856 ms 27468 KB Output is correct
3 Correct 482 ms 19732 KB Output is correct
4 Runtime error 1012 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -