답안 #526758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526758 2022-02-16T04:05:14 Z beepbeepsheep Izbori (COCI22_izbori) C++17
15 / 110
26 ms 5020 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define endl '\n'
const ll inf=1e15;
const ll mod=1e9+7;
const ll maxn=2e5+5;

ll arr[maxn];
vector<ll> v;
ll fen[2*maxn];
void upd(ll pos){
    while (pos<2*maxn){
        fen[pos]++;
        pos+=(pos&-pos);
    }
}
ll query(ll pos){
    ll ans=0;
    while (pos){
        ans+=fen[pos];
        pos-=(pos&-pos);
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll ans=0;
    for (int i=1;i<=2;i++){
        ll tot=0;
        memset(fen,0,sizeof(fen));
        upd(2e5+1);
        for (int j=0;j<n;j++){
            if (arr[j]==i){
                tot++;
            }else{
                tot--;
            }
            upd(tot+2e5+1);
            ans+=query(tot+2e5);
        }
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4488 KB Output is correct
2 Correct 20 ms 4808 KB Output is correct
3 Correct 15 ms 4244 KB Output is correct
4 Correct 21 ms 4804 KB Output is correct
5 Correct 22 ms 4916 KB Output is correct
6 Correct 26 ms 4940 KB Output is correct
7 Correct 25 ms 5020 KB Output is correct
8 Correct 23 ms 4928 KB Output is correct
9 Correct 23 ms 4912 KB Output is correct
10 Correct 23 ms 4988 KB Output is correct
11 Correct 22 ms 5000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -