답안 #655135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655135 2022-11-03T08:22:13 Z snpmrnhlol Meteors (POI11_met) C++17
74 / 100
1919 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v[400000],v2[400000],l[400000],r[400000];
ll v3[400000],v4[400000],v5[400000];
vector <ll> v6[400000];
vector <ll> v7[400000];
class fenwick{
    ll fen[400001];
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 <= 400000;i+=(i&-i))fen[i]+=nr;
    }
    void empt(){
        for(ll i = 0;i <= 400000;i++)fen[i] = 0;
        //cout<<"emptied\n";
    }
};
fenwick fen;
bool calc(ll nr,ll nr2){
    ll r = 0;
    for(auto i:v7[nr]){
        //cout<<i<<' '<<fen.query(i)<<'\n';
        r+=fen.query(i);
        if(r >= nr2)return 1;
    }
    return 0;
}
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 < 30;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
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 22368 KB Output is correct
2 Correct 18 ms 22356 KB Output is correct
3 Correct 16 ms 22304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 22356 KB Output is correct
2 Correct 17 ms 22324 KB Output is correct
3 Correct 16 ms 22476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 25216 KB Output is correct
2 Correct 245 ms 28400 KB Output is correct
3 Correct 170 ms 27468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 194 ms 26772 KB Output is correct
2 Correct 193 ms 26700 KB Output is correct
3 Correct 225 ms 28960 KB Output is correct
4 Correct 42 ms 25676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 25888 KB Output is correct
2 Correct 313 ms 29032 KB Output is correct
3 Correct 193 ms 23508 KB Output is correct
4 Correct 170 ms 28128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 24448 KB Output is correct
2 Correct 224 ms 26684 KB Output is correct
3 Correct 135 ms 24920 KB Output is correct
4 Correct 263 ms 30184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1433 ms 55784 KB Output is correct
2 Correct 1919 ms 34168 KB Output is correct
3 Correct 901 ms 30796 KB Output is correct
4 Runtime error 905 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1652 ms 53512 KB Output is correct
2 Correct 1115 ms 34172 KB Output is correct
3 Correct 769 ms 30496 KB Output is correct
4 Runtime error 906 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -