답안 #762450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762450 2023-06-21T12:08:01 Z Chal1shkan Meteors (POI11_met) C++14
74 / 100
5197 ms 49480 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];
    }
    int 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!!!
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14420 KB Output is correct
2 Correct 11 ms 14552 KB Output is correct
3 Correct 11 ms 14520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14548 KB Output is correct
2 Correct 9 ms 14548 KB Output is correct
3 Correct 11 ms 14492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 419 ms 18092 KB Output is correct
2 Correct 498 ms 20108 KB Output is correct
3 Correct 534 ms 19680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 509 ms 19144 KB Output is correct
2 Correct 475 ms 19108 KB Output is correct
3 Correct 476 ms 20172 KB Output is correct
4 Correct 78 ms 18420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 18544 KB Output is correct
2 Correct 322 ms 20812 KB Output is correct
3 Correct 236 ms 15312 KB Output is correct
4 Correct 487 ms 20116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 467 ms 17616 KB Output is correct
2 Correct 420 ms 19196 KB Output is correct
3 Correct 453 ms 17948 KB Output is correct
4 Correct 499 ms 21460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4962 ms 49480 KB Output is correct
2 Incorrect 2233 ms 36896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5197 ms 48152 KB Output is correct
2 Incorrect 1274 ms 36864 KB Output isn't correct
3 Halted 0 ms 0 KB -