답안 #547203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547203 2022-04-09T19:39:25 Z urosk Meteors (POI11_met) C++14
74 / 100
3420 ms 65536 KB
// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x)
// __builtin_clz(x) vodece nule
// __builtin_clzll(x)
// __builtin_ctz(x) nule na pocetku
// __builtin_ctzll(x)
// 2000000011
// 2000000033
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) ((ll)(a.size()))
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pi 3.14159265358979323846
#define here cerr<<"=============================================================================\n"
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}}
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}

void setIO(string inoutname)
{
	freopen((inoutname+".in").c_str(),"r",stdin);
    	freopen((inoutname+".out").c_str(),"w",stdout);
}
#define mod 1
ll gcd(ll a, ll b)
{
   if(b==0) return a;
   if(a==0) return b;
   if(a>=b)  return gcd(a%b,b);
   return  gcd(a,b%a);
}
ll lcm(ll a,ll b){
   return (a/gcd(a,b))*b;
}
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
	if(x==mod) x = 0;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
ll po(ll x,ll y){
    if(y==0) return 1LL;
    ll ans = po(x,y/2);
    ans = mul(ans,ans);
    if(y&1) ans = mul(ans,x);
    return ans;
}
ll inv(ll x){return po(x,mod-2);}

#define maxn 300005
ll n,m;
ll a[maxn];
ll b[maxn];
vector<ll> v[maxn];
vector<ll> q[maxn];
ll L[maxn],R[maxn],rez[maxn];
ll k;
struct met{
    ll l,r,x;
};
vector<met> metr;
ll t[4*maxn];
void upd(ll v,ll tl,ll tr,ll l,ll r,ll x){
    //cerr<<tl<< " "<<tr<< " "<<l<< " "<<r<<endl;
    if(l>r) return;
    if(tl==l&&tr==r){
        t[v]+=x;
        return;
    }
    ll mid = (tl+tr)/2;
    upd(2*v,tl,mid,l,min(mid,r),x);
    upd(2*v+1,mid+1,tr,max(l,mid+1),r,x);
}
void init(ll v,ll tl,ll tr){
    t[v] = 0;
    if(tl==tr) return;
    ll mid = (tl+tr)/2;
    init(2*v,tl,mid);
    init(2*v+1,mid+1,tr);
}
ll get(ll v,ll tl,ll tr,ll i){
    if(tl==tr) return t[v];
    ll mid = (tl+tr)/2;
    if(i<=mid) return t[v] + get(2*v,tl,mid,i);
    return t[v] + get(2*v+1,mid+1,tr,i);
}
void tc(){
	daj_mi_malo_vremena
    cin >> m >> n;
    for(ll i = 1;i<=n;i++){
        cin >> a[i];
        v[a[i]].pb(i);
    }
    for(ll i = 1;i<=m;i++) cin >> b[i];
    cin >> k;
    metr.pb({-1,-1,-1});
    for(ll i = 1;i<=k;i++){
        ll l,r,x; cin >> l >> r >> x;
        metr.pb({l,r,x});
    }
    for(ll i = 1;i<=m;i++) L[i] = 1,R[i] = k,rez[i] = -1;
    bool menja = 1;
    while(menja){
        for(ll i = 1;i<=k;i++) q[i].clear();
        init(1,1,n);
        menja = 0;
        for(ll i = 1;i<=m;i++){
            if(L[i]>R[i]) continue;
            menja = 1;
            ll mid = (L[i]+R[i])/2;
            q[mid].pb(i);
        }
        /*here;
        for(ll i = 1;i<=k;i++){
            cerr<<"mid: "<<i<<endl;
            for(ll x : q[i]) cerr<<x<< " ";
            cerr<<endl;
        }*/
        for(ll i = 1;i<=k;i++){
            ll l = metr[i].l;
            ll r = metr[i].r;
            ll x = metr[i].x;
            //cerr<<l<< " "<<r<<" "<<x<<endl;
            if(l<=r){
                upd(1,1,n,l,r,x);
            }else{
                upd(1,1,n,1,r,x);
                upd(1,1,n,l,n,x);
            }
            for(ll x : q[i]){
                ll sum = 0;
                for(ll y : v[x]){
                    sum+=get(1,1,n,y);
                    if(sum>=b[x]) break;
                }
                //cerr<<x<< " "<<sum<<endl;
                if(sum>=b[x]){
                    rez[x] = i;
                    R[x] = i-1;
                }else L[x] = i+1;
            }
        }
        //here;
    }
    for(ll i = 1;i<=m;i++){
        if(rez[i]==-1) cout<<"NIE"<<endl;
        else cout<<rez[i]<<endl;
    }
}
int main(){
	daj_mi_malo_vremena
	//setIO("lol");
	int t; t = 1;
	while(t--){
		tc();
	}
	return 0;
}

Compilation message

met.cpp: In function 'void setIO(std::string)':
met.cpp:48:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:49:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14548 KB Output is correct
2 Correct 11 ms 14584 KB Output is correct
3 Correct 10 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14552 KB Output is correct
2 Correct 10 ms 14548 KB Output is correct
3 Correct 11 ms 14660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 294 ms 18608 KB Output is correct
2 Correct 356 ms 22348 KB Output is correct
3 Correct 379 ms 20772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 327 ms 19984 KB Output is correct
2 Correct 372 ms 19984 KB Output is correct
3 Correct 340 ms 22388 KB Output is correct
4 Correct 80 ms 19204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 18976 KB Output is correct
2 Correct 302 ms 22588 KB Output is correct
3 Correct 168 ms 16156 KB Output is correct
4 Correct 327 ms 21512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 308 ms 17704 KB Output is correct
2 Correct 281 ms 20060 KB Output is correct
3 Correct 304 ms 18184 KB Output is correct
4 Correct 380 ms 23688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3420 ms 56788 KB Output is correct
2 Correct 1320 ms 35120 KB Output is correct
3 Correct 776 ms 23000 KB Output is correct
4 Runtime error 2164 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3402 ms 54712 KB Output is correct
2 Correct 852 ms 35116 KB Output is correct
3 Correct 663 ms 23100 KB Output is correct
4 Runtime error 1544 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -