답안 #761616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761616 2023-06-20T05:36:48 Z vjudge1 Meteors (POI11_met) C++17
100 / 100
2613 ms 45636 KB
#include "bits/stdc++.h"
using namespace std;

// #define ORD_SET
// #define ROPE
#ifdef ORD_SET
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    template<typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif
#ifdef ROPE
    #include <ext/rope>
    using namespace __gnu_cxx;
#endif        

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void ioigold2024insh() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
void pre(ll a) { cout<<fixed<<setprecision(a); }
ll bit(ll a) { return __builtin_popcountll(a); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }

struct sn { ll l, r, x; };
const ll mod = 1e9+7, inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll N = 3e5+5;
ll a[N], b[N], l[N], r[N], x[N], d[N], sum[N], t[N], upd[N], B = 547;
vector<ll> gr[600], g[N];

void kigash() {
    ll n, m;
    cin>>m>>n;
    for(ll i=1; i<=n; i++) cin>>a[i], g[a[i]].pb(i);
    for(ll i=1; i<=m; i++) cin>>b[i], t[i] = -1;
    ll q;
    cin>>q, B = min(B, q);
    for(ll i=1; i<=q; i++) {
        cin>>l[i]>>r[i]>>x[i];
        if(l[i]>r[i]) d[1] += x[i], d[r[i]+1] -= x[i], d[l[i]] += x[i], d[n+1] -= x[i];
        else d[l[i]] += x[i], d[r[i]+1] -= x[i];
        if(i%B==0 || i==q) {
            for(ll j=1; j<=n; j++) d[j] += d[j-1];
            for(ll j=1; j<=m; j++) sum[j] = 0;
            for(ll j=1; j<=n; j++) sum[a[j]] += d[j];
            for(ll j=1; j<=m; j++) {
                if(sum[j]>=b[j] && t[j]==-1) t[j] = (i-1)/B, gr[(i-1)/B].pb(j); 
            }
            for(ll j=n; j>=1; j--) d[j] -= d[j-1];
        }
    }
    for(ll i=0; i<=n; i++) d[i] = 0;
    for(ll i=0; i<=m; i++) sum[i] = 0;
    for(ll i=1; i<=q; i++) {
        for(auto num: gr[(i-1)/B]) {
            if(upd[num]) continue;
            if(g[num].empty()) continue;
            if(l[i]>r[i]) {
                ll R = upper_bound(all(g[num]), r[i])-g[num].begin()-1;
                sum[num] += (R+1)*x[i];
                ll L = lower_bound(all(g[num]), l[i])-g[num].begin();
                sum[num] += (sz(g[num])-L)*x[i];
            }
            else {
                ll L = lower_bound(all(g[num]), l[i])-g[num].begin();
                if(L==sz(g[num])) continue;
                ll R = upper_bound(all(g[num]), r[i])-g[num].begin()-1;
                if(R==-1) continue;
                sum[num] += (R-L+1)*x[i];
            }
            if(sum[num]>=b[num]) t[num] = i, upd[num] = 1;
        }
        if(l[i]>r[i]) d[1] += x[i], d[r[i]+1] -= x[i], d[l[i]] += x[i], d[n+1] -= x[i];
        else d[l[i]] += x[i], d[r[i]+1] -= x[i];
        if(i%B==0) {
            for(ll j=1; j<=n; j++) d[j] += d[j-1];
            for(ll j=1; j<=m; j++) sum[j] = 0;
            for(ll j=1; j<=n; j++) sum[a[j]] += d[j];
            for(ll j=n; j>=1; j--) d[j] -= d[j-1];
        }
    }
    for(ll i=1; i<=m; i++) {
        if(t[i]==-1) cout<<"NIE\n";
        else cout<<t[i]<<"\n";
    }
    return;
}

signed main(/*Kigash Amir*/) {
    // freopen("");
    ioigold2024insh();
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) kigash();
    exit(0);
}

Compilation message

met.cpp:18: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
   18 | #pragma comment(linker, "/stack:200000000")
      | 
met.cpp: In function 'void freopen(std::string)':
met.cpp:31:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:31:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 3 ms 7508 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 3 ms 7508 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 10120 KB Output is correct
2 Correct 44 ms 11048 KB Output is correct
3 Correct 126 ms 10700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 10472 KB Output is correct
2 Correct 76 ms 10492 KB Output is correct
3 Correct 102 ms 11408 KB Output is correct
4 Correct 26 ms 9616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 10220 KB Output is correct
2 Correct 71 ms 11100 KB Output is correct
3 Correct 13 ms 8660 KB Output is correct
4 Correct 93 ms 10984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 9856 KB Output is correct
2 Correct 76 ms 10460 KB Output is correct
3 Correct 47 ms 10060 KB Output is correct
4 Correct 105 ms 11396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1490 ms 29152 KB Output is correct
2 Correct 1189 ms 29372 KB Output is correct
3 Correct 46 ms 15692 KB Output is correct
4 Correct 2613 ms 43632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1705 ms 28380 KB Output is correct
2 Correct 1181 ms 27992 KB Output is correct
3 Correct 42 ms 15580 KB Output is correct
4 Correct 2217 ms 45636 KB Output is correct