답안 #765039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765039 2023-06-24T07:50:16 Z dxz05 Izbori (COCI22_izbori) C++17
40 / 110
3000 ms 10488 KB
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx,avx2")

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
#define BIT(x, i) (((x) >> (i)) & 1)
//#define endl '\n'

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 2e5 + 30;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

int a[N];

void solve(){
    int n;
    cin >> n;

    set<int> values;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        values.insert(a[i]);
    }

    ll ans = 0;
    for (int x : values){
        int p = 0;
        indexed_multiset<int> s;
        s.insert(0);

        for (int i = 1; i <= n; i++){
            p += (a[i] == x ? 1 : -1);
            ans += s.order_of_key(p);
            s.insert(p);
        }
    }

    cout << ans << endl;

}

int main(){
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int test_cases = 1;
//    cin >> test_cases;

    for (int test = 1; test <= test_cases; test++){
        // cout << (solve() ? "YES" : "NO") << endl;
        solve();
    }

#ifdef LOCAL
    cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:58:13: warning: unused variable 'startTime' [-Wunused-variable]
   58 |     clock_t startTime = clock();
      |             ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 81 ms 408 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 444 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 440 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 6984 KB Output is correct
2 Correct 101 ms 9160 KB Output is correct
3 Correct 56 ms 5464 KB Output is correct
4 Correct 101 ms 9572 KB Output is correct
5 Correct 103 ms 9848 KB Output is correct
6 Correct 110 ms 10440 KB Output is correct
7 Correct 115 ms 10484 KB Output is correct
8 Correct 113 ms 10380 KB Output is correct
9 Correct 117 ms 10400 KB Output is correct
10 Correct 116 ms 10488 KB Output is correct
11 Correct 177 ms 10424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 81 ms 408 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 444 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 440 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 74 ms 6984 KB Output is correct
19 Correct 101 ms 9160 KB Output is correct
20 Correct 56 ms 5464 KB Output is correct
21 Correct 101 ms 9572 KB Output is correct
22 Correct 103 ms 9848 KB Output is correct
23 Correct 110 ms 10440 KB Output is correct
24 Correct 115 ms 10484 KB Output is correct
25 Correct 113 ms 10380 KB Output is correct
26 Correct 117 ms 10400 KB Output is correct
27 Correct 116 ms 10488 KB Output is correct
28 Correct 177 ms 10424 KB Output is correct
29 Correct 177 ms 10380 KB Output is correct
30 Execution timed out 3077 ms 3836 KB Time limit exceeded
31 Halted 0 ms 0 KB -