Submission #1048293

# Submission time Handle Problem Language Result Execution time Memory
1048293 2024-08-08T06:31:00 Z fgbdvcs Meteors (POI11_met) C++14
74 / 100
883 ms 33392 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front

int const maxn = 3e5+7;
const ll INF = LLONG_MAX;

int n , m , q;
int x[maxn] ;
int l[maxn] , r[maxn];
int le[maxn] , ri[maxn];
ll v[maxn] , a[maxn];
vector<int> adj[maxn];
vector<int> stage , temp;

struct Fw
{
    ll bit[maxn];

    Fw()
    {
        memset(bit , 0 , sizeof(bit));
    }

    void Clear()
    {
        memset(bit , 0 , sizeof(bit));
    }

    void Upd(int u , ll v)
    {
        int idx = u;
        while(idx <= m){
                bit[idx] += v;
                idx += (idx & (- idx));
        }
    }

    ll Get(int u)
    {
        ll re = 0;
        int idx = u;
        while(idx){
                re += bit[idx];
                idx -= (idx & (- idx));
        }
        return re;
    }
};

Fw Fen;

void Update(int pos)
{
    Fen.Upd(l[pos] , v[pos]);
    Fen.Upd(r[pos] + 1 , - v[pos]);
    if(l[pos] > r[pos]){
            Fen.Upd(1 , v[pos]);
    }
}

ll Get_sum(int pos)
{
    ll re = 0;
    for(auto u : adj[pos]){
            re += Fen.Get(u);
    }
    return re;
}

void Input()
{
    cin >> n >> m;
    for(int i = 1 ; i <= m ; i ++){
            cin >> x[i];
            adj[x[i]].pb(i);
    }
    for(int i = 1 ; i <= n ; i ++){
            cin >> a[i];
    }

    cin >> q;
    for(int i = 1 ; i <= q ; i ++){
            cin >> l[i] >> r[i] >> v[i];
    }
}

bool cmp(int x , int y)
{
    return (le[x] + ri[x]) / 2 < (le[y] + ri[y]) / 2;
}

void Solve()
{

    for(int i = 1 ; i <= n ; i ++){
            stage.pb(i);
            le[i] = 1;
            ri[i] = q;
    }

    while(stage.size() != 0){
            sort(stage.begin() , stage.end() , cmp);

            int run = 1;

            for(auto u : stage){
                    int mid = (le[u] + ri[u]) / 2;
                    while(run <= mid){
                            Update(run);
                            run ++;
                    }

                    ll s = Get_sum(u);
                    if(s < a[u]) le[u] = mid + 1;
                    else ri[u] = mid - 1;

                    if(le[u] <= ri[u]) temp.pb(u);
            }

           // cout << "Check " << "\n";
          //  for(int i = 1 ; i <= n ; i ++){
          //          cout << le[i] << " " << ri[i] << "\n";
          //  }

            swap(stage , temp);
            temp.clear();
            Fen.Clear();
    }

    for(int i = 1 ; i <= n ; i ++){
          //  cout << "le " << le[i] << "\n";
            le[i] > q ? cout << "NIE" : cout << le[i];
            cout << "\n";
    }
}

int main()
{
   // freopen(".INP","r",stdin);
   // freopen(".OUT","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while(tt--){
            Input();
            Solve();
    }
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 3 ms 19148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19032 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 3 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 20548 KB Output is correct
2 Correct 80 ms 21340 KB Output is correct
3 Correct 67 ms 21072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 20828 KB Output is correct
2 Correct 59 ms 20984 KB Output is correct
3 Correct 80 ms 21588 KB Output is correct
4 Correct 21 ms 20316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 20568 KB Output is correct
2 Correct 66 ms 21592 KB Output is correct
3 Correct 15 ms 19544 KB Output is correct
4 Correct 63 ms 21292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 20568 KB Output is correct
2 Correct 72 ms 21072 KB Output is correct
3 Correct 39 ms 20568 KB Output is correct
4 Correct 77 ms 21596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 883 ms 33392 KB Output is correct
2 Incorrect 581 ms 29536 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 880 ms 32924 KB Output is correct
2 Incorrect 500 ms 28116 KB Output isn't correct
3 Halted 0 ms 0 KB -