답안 #526761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526761 2022-02-16T04:10:41 Z beepbeepsheep Izbori (COCI22_izbori) C++17
40 / 110
3000 ms 6688 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];
        v.push_back(arr[i]);
    }
    sort(v.begin(),v.end());
    vector<ll> newv;
    for (auto u:v){
        if (newv.empty()) newv.push_back(u);
        else if (newv.back()!=u) newv.push_back(u);
    }
    for (int i=0;i<n;i++){
        arr[i]=lower_bound(newv.begin(),newv.end(),arr[i])-newv.begin();
    }
    ll ans=0;
    for (int i=0;i<newv.size();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;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i=0;i<newv.size();i++){
      |                  ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3420 KB Output is correct
2 Correct 6 ms 3400 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3420 KB Output is correct
2 Correct 6 ms 3400 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 102 ms 3472 KB Output is correct
8 Correct 16 ms 3452 KB Output is correct
9 Correct 4 ms 3404 KB Output is correct
10 Correct 4 ms 3404 KB Output is correct
11 Correct 4 ms 3404 KB Output is correct
12 Correct 4 ms 3408 KB Output is correct
13 Correct 4 ms 3404 KB Output is correct
14 Correct 4 ms 3408 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 4 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 5640 KB Output is correct
2 Correct 25 ms 6212 KB Output is correct
3 Correct 15 ms 5060 KB Output is correct
4 Correct 30 ms 6328 KB Output is correct
5 Correct 30 ms 6516 KB Output is correct
6 Correct 30 ms 6648 KB Output is correct
7 Correct 29 ms 6588 KB Output is correct
8 Correct 29 ms 6584 KB Output is correct
9 Correct 29 ms 6684 KB Output is correct
10 Correct 29 ms 6688 KB Output is correct
11 Correct 20 ms 6588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3420 KB Output is correct
2 Correct 6 ms 3400 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 102 ms 3472 KB Output is correct
8 Correct 16 ms 3452 KB Output is correct
9 Correct 4 ms 3404 KB Output is correct
10 Correct 4 ms 3404 KB Output is correct
11 Correct 4 ms 3404 KB Output is correct
12 Correct 4 ms 3408 KB Output is correct
13 Correct 4 ms 3404 KB Output is correct
14 Correct 4 ms 3408 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 4 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 20 ms 5640 KB Output is correct
19 Correct 25 ms 6212 KB Output is correct
20 Correct 15 ms 5060 KB Output is correct
21 Correct 30 ms 6328 KB Output is correct
22 Correct 30 ms 6516 KB Output is correct
23 Correct 30 ms 6648 KB Output is correct
24 Correct 29 ms 6588 KB Output is correct
25 Correct 29 ms 6584 KB Output is correct
26 Correct 29 ms 6684 KB Output is correct
27 Correct 29 ms 6688 KB Output is correct
28 Correct 20 ms 6588 KB Output is correct
29 Correct 31 ms 6588 KB Output is correct
30 Execution timed out 3042 ms 4408 KB Time limit exceeded
31 Halted 0 ms 0 KB -