답안 #684507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684507 2023-01-21T11:19:17 Z bachhoangxuan Meteors (POI11_met) C++17
100 / 100
1088 ms 65220 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define pii pair<int,int>
const long long inf=1e18;
const int mod=998244353;
const int maxn=300005;
const int maxl=20;
const int maxa=1000005;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
struct qry{
    int l,r,val;
};
int n,m,q,a[maxn],p[maxn],ans[maxn];
vector<int> x[maxn],ss[maxn];
qry que[maxn];
namespace BIT{
    long long bit[maxn];
    void update(int l,int r,int val){
        for(int i=l;i<=m;i+=(i&(-i))) bit[i]+=val;
        for(int i=r+1;i<=m;i+=(i&(-i))) bit[i]-=val;
    }
    void up(int l,int r,int val){
        if(l>r){update(l,m,val);update(1,r,val);}
        else update(l,r,val);
    }
    long long query(int x){
        long long res=0;
        for(int i=x;i>=1;i-=(i&(-i))) res+=bit[i];
        return res;
    }
}
void cal(int l,int r){
    int mid=(l+r)>>1,lt=(l+mid-1)>>1,rt=(mid+r+1)>>1;
    for(int v:ss[mid]){
        long long sum=0;
        for(int d:x[v]) sum=min(sum+BIT::query(d),inf);
        if(sum>=p[v]) ans[v]=mid;
        if(sum>=p[v] && l<mid) ss[lt].push_back(v);
        else if(sum<p[v] && r>mid) ss[rt].push_back(v);
    }
    if(r>mid){
        for(int i=mid+1;i<=rt;i++) BIT::up(que[i].l,que[i].r,que[i].val);
        cal(mid+1,r);
        for(int i=mid+1;i<=rt;i++) BIT::up(que[i].l,que[i].r,-que[i].val);
    }
    if(l<mid){
        for(int i=lt+1;i<=mid;i++) BIT::up(que[i].l,que[i].r,-que[i].val);
        cal(l,mid-1);
        for(int i=lt+1;i<=mid;i++) BIT::up(que[i].l,que[i].r,que[i].val);
    }
}
void solve(){
    cin >> n >> m;
    for(int i=1;i<=m;i++){cin >> a[i];x[a[i]].push_back(i);}
    for(int i=1;i<=n;i++) cin >> p[i];
    cin >> q;
    for(int i=1;i<=q;i++) cin >> que[i].l >> que[i].r >> que[i].val;
    int mid=(1+q)>>1;
    for(int i=1;i<=n;i++) ss[mid].push_back(i);
    for(int i=1;i<=mid;i++) BIT::up(que[i].l,que[i].r,que[i].val);
    cal(1,q);
    for(int i=1;i<=n;i++){
        if(ans[i]) cout << ans[i] << '\n';
        else cout << "NIE\n";
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t=1;//cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 11 ms 14512 KB Output is correct
3 Correct 9 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14520 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 10 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 16372 KB Output is correct
2 Correct 89 ms 18148 KB Output is correct
3 Correct 76 ms 17964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 17384 KB Output is correct
2 Correct 79 ms 17436 KB Output is correct
3 Correct 97 ms 18368 KB Output is correct
4 Correct 29 ms 16728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 16760 KB Output is correct
2 Correct 72 ms 18840 KB Output is correct
3 Correct 42 ms 15064 KB Output is correct
4 Correct 79 ms 18320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 15948 KB Output is correct
2 Correct 82 ms 17352 KB Output is correct
3 Correct 61 ms 16148 KB Output is correct
4 Correct 93 ms 19532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 840 ms 34472 KB Output is correct
2 Correct 545 ms 22800 KB Output is correct
3 Correct 189 ms 17524 KB Output is correct
4 Correct 955 ms 61536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 755 ms 33268 KB Output is correct
2 Correct 603 ms 22736 KB Output is correct
3 Correct 160 ms 16716 KB Output is correct
4 Correct 1088 ms 65220 KB Output is correct