Submission #655133

# Submission time Handle Problem Language Result Execution time Memory
655133 2022-11-03T08:17:10 Z snpmrnhlol Meteors (POI11_met) C++17
74 / 100
1030 ms 50064 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v[300000],v2[300000],l[300000],r[300000];
ll v3[300000],v4[300000],v5[300000];
vector <ll> v6[300000];
vector <ll> v7[300000];
class fenwick{
    ll fen[300001];
public:
    ll query(ll pos){
        pos++;
        ll r = 0;
        for(ll i = pos;i > 0;i-=(i&-i))r+=fen[i];
        //cout<<"query:"<<pos - 1<<",result:"<<r<<'\n';
        return r;
    }
    void add(ll pos,ll nr){
        //cout<<"added:"<<pos<<','<<nr<<'\n';
        pos++;
        for(ll i = pos;i <= 300000;i+=(i&-i))fen[i]+=nr;
    }
    void empt(){
        for(ll i = 0;i <= 300000;i++)fen[i] = 0;
        //cout<<"emptied\n";
    }
};
fenwick fen;
ll calc(ll nr){
    ll r = 0;
    for(auto i:v7[nr]){
        //cout<<i<<' '<<fen.query(i)<<'\n';
        r+=fen.query(i);
    }
    return r;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,m,i,q,j;
    cin>>n>>m;
    for(i = 0;i < m;i++)cin>>v[i],v[i]--,v7[v[i]].push_back(i);;
    for(i = 0;i < n;i++){
        cin>>v2[i];
    }
    cin>>q;
    for(i = 0;i < q;i++){
        cin>>v3[i]>>v4[i]>>v5[i];
        v3[i]--;
        v4[i]--;
    }
    for(i = 0;i < n;i++)l[i] = 0,r[i] = q;
    for(i = 0;i < 20;i++){
        for(j = 0;j < q;j++)v6[j].clear();
        fen.empt();
        for(j = 0;j < n;j++){
            if(l[j] != r[j]){
                v6[(l[j] + r[j])/2].push_back(j);
            }
        }
        ///simulate
        for(j = 0;j < q;j++){
            //cout<<"adding query:"<<j<<',';
            if(v3[j] <= v4[j]){
                fen.add(v3[j],v5[j]);
                fen.add(v4[j] + 1,-v5[j]);
            }else{
                swap(v3[j],v4[j]);
                fen.add(0,v5[j]);
                fen.add(v3[j] + 1,-v5[j]);
                fen.add(v4[j],v5[j]);
                swap(v3[j],v4[j]);
            }
            //cout<<'\n';
            for(auto p:v6[j]){
                //cout<<calc(p)<<' '<<j<<' '<<p<<'\n';
                if(calc(p) >= v2[p]){
                    r[p] = j;
                }else{
                    l[p] = j + 1;
                }
            }
        }
    }
    for(i = 0;i < n;i++){
        if(l[i] == q)cout<<"NIE";
        else cout<<l[i] + 1;
        cout<<'\n';
    }
    return 0;
}
/**
3 5
1 3 2 1 3
8 1 8
3
4 2 4
1 3 1
3 5 2
**/
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16852 KB Output is correct
2 Correct 12 ms 16852 KB Output is correct
3 Correct 12 ms 16896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16852 KB Output is correct
2 Correct 11 ms 16828 KB Output is correct
3 Correct 16 ms 16916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 19788 KB Output is correct
2 Correct 184 ms 23112 KB Output is correct
3 Correct 124 ms 22172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 21292 KB Output is correct
2 Correct 143 ms 21352 KB Output is correct
3 Correct 177 ms 23476 KB Output is correct
4 Correct 39 ms 20428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 20300 KB Output is correct
2 Correct 212 ms 23688 KB Output is correct
3 Correct 132 ms 18192 KB Output is correct
4 Correct 122 ms 22736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 18920 KB Output is correct
2 Correct 165 ms 21352 KB Output is correct
3 Correct 96 ms 19572 KB Output is correct
4 Correct 172 ms 24872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1020 ms 50064 KB Output is correct
2 Incorrect 758 ms 28784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1030 ms 47904 KB Output is correct
2 Incorrect 759 ms 28780 KB Output isn't correct
3 Halted 0 ms 0 KB -