답안 #866621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866621 2023-10-26T14:16:47 Z asdfghjk Meteors (POI11_met) C++17
74 / 100
629 ms 65536 KB
/// tree bends in youth
/// 24  .10.2023
/// success is doing same thing in every single day!!!
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
using namespace std;
const ll N = 4e5+ 5;
const ll NN =2e6 + 5;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LG = 18;
ll z[N],x[N];
ll t[4 * N],p[4 * N],c[N],b[N];
pair<ll,ll> seq[N];
set <ll> MID[N],rg[N];
ll ok[N];
void build(ll v,ll l,ll r){
    p[v] = 0;
    if(l == r){
        t[v] = 0;
        return;
    }
    ll mid = (l + r) / 2ll;
    build(v+v,l,mid);
    build(v+v+1,mid+1,r);
}
void push(ll v,ll l,ll r){
    if(p[v] > 0){
        if(l != r){
            p[v+v] += p[v];
            p[v+v+1] += p[v];
        }
        else{
            t[v] +=p[v];
        }
        p[v] = 0;
    }
}
void upd(ll v,ll l,ll r,ll ql,ll qr,ll x){
    push(v,l,r);
    if(l >= ql && qr >= r){
        p[v] += x;
        push(v,l,r);
        return;
    }
    if(qr < l || r < ql)return;
    ll mid = (l + r) / 2ll;
    upd(v+v,l,mid,ql,qr,x);
    upd(v+v+1,mid+1,r,ql,qr,x);
}
ll get(ll v,ll l,ll r,ll x){
    push(v,l,r);
    if(l == r)return t[v];
    ll mid = (l + r) / 2ll;
    if(x <= mid)return get(v+v,l,mid,x);
    else return get(v+v+1,mid + 1,r,x);
}
void solve(){
    ll n,m;
    cin >> n >> m;
    for(ll i = 1;i <= m;i++){
        ll u;cin >> u;
        rg[u].insert(i);
    }
    for(ll i= 1;i <= n;i++){
        cin >> b[i];
    }
    ll q;
    cin >> q;
    for(ll i = 1;i <=q;i++){
        cin >> z[i] >> x[i] >> c[i];
    }
    for(ll i = 1;i <= n;i++){
        seq[i] = {1,q};
    }
    ll tt = 18;
    while(tt--){
        for(ll i = 1;i <= n;i++){
            ll md = (seq[i].F + seq[i].S) / 2ll;
            MID[md].insert(i);
        }
        build(1,1,m);
        for(ll i = 1;i <= q;i++){
            if(z[i] > x[i]){
                upd(1,1,m,1,x[i],c[i]);
                upd(1,1,m,z[i],m,c[i]);
            }
            else{
                upd(1,1,m,z[i],x[i],c[i]);
            }
            for(ll to : MID[i]){
                ll sum=  0;
                for(ll d : rg[to]){
                    sum += get(1,1,m,d);
                    if(sum >= b[to])break;
                }
                if(sum >= b[to]){
                    ok[to] = 1;
                    seq[to].S=  i;
                }
                else {
                    seq[to].F = i + 1;
                }
            }
        }
        for(ll i = 1;i <= q;i++){
            MID[i].clear();
        }
    }
    for(ll i = 1;i<=n;i++){
        if(seq[i].F <= q){
            cout << seq[i].F << '\n';
        }
        else{
            cout <<  "NIE\n";
        }
    }
}
main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ll abd= 1;
   // cin >> abd;
    for(ll i = 1;i <= abd;i++){
//        cout << "Case " << i << ":\n";
        solve();
    }
}

Compilation message

met.cpp:123:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  123 | main (){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 39624 KB Output is correct
2 Correct 17 ms 39652 KB Output is correct
3 Correct 18 ms 51804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 50344 KB Output is correct
2 Correct 14 ms 39636 KB Output is correct
3 Correct 18 ms 51804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 57144 KB Output is correct
2 Correct 629 ms 58444 KB Output is correct
3 Correct 574 ms 57620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 513 ms 57340 KB Output is correct
2 Correct 529 ms 57408 KB Output is correct
3 Correct 619 ms 60516 KB Output is correct
4 Correct 134 ms 57384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 254 ms 57192 KB Output is correct
2 Correct 414 ms 60340 KB Output is correct
3 Correct 234 ms 52280 KB Output is correct
4 Correct 521 ms 57836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 510 ms 57172 KB Output is correct
2 Correct 468 ms 57424 KB Output is correct
3 Correct 464 ms 56924 KB Output is correct
4 Correct 579 ms 60240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 130 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 126 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -