Submission #526814

# Submission time Handle Problem Language Result Execution time Memory
526814 2022-02-16T08:00:40 Z joelau Izbori (COCI22_izbori) C++14
25 / 110
3000 ms 12420 KB
#include <bits/stdc++.h>
using namespace std;

long long N,A[200005], freq[400005];
vector<long long> A1, lst[200005];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (long long i = 0; i < N; ++i) {
        cin >> A[i];
        A1.push_back(A[i]);
    }
    sort(A1.begin(),A1.end());
    A1.resize(unique(A1.begin(),A1.end())-A1.begin());
    for (long long i = 0; i < N; ++i) {
        A[i] = lower_bound(A1.begin(),A1.end(),A[i]) - A1.begin();
        lst[A[i]].push_back(i);
    }
    long long ans = 0;
    for (long long n = 0; n < N; ++n) {
        long long cnt = N, last = 0;
        memset(freq,0,sizeof(freq));
        freq[cnt]++;
        for (long long i = 0, j = 0; i < N; ++i) {
            if (j < lst[n].size() && i == lst[n][j]) last += freq[cnt++], j++;
            else last -= freq[--cnt];
            ans += last, freq[cnt]++;
        }
    }
    cout << ans;

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:26:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             if (j < lst[n].size() && i == lst[n][j]) last += freq[cnt++], j++;
      |                 ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8140 KB Output is correct
2 Correct 9 ms 8076 KB Output is correct
3 Correct 25 ms 8140 KB Output is correct
4 Correct 25 ms 8092 KB Output is correct
5 Correct 25 ms 8140 KB Output is correct
6 Correct 25 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8140 KB Output is correct
2 Correct 9 ms 8076 KB Output is correct
3 Correct 25 ms 8140 KB Output is correct
4 Correct 25 ms 8092 KB Output is correct
5 Correct 25 ms 8140 KB Output is correct
6 Correct 25 ms 8140 KB Output is correct
7 Correct 69 ms 8184 KB Output is correct
8 Correct 14 ms 8140 KB Output is correct
9 Correct 160 ms 8220 KB Output is correct
10 Correct 145 ms 8140 KB Output is correct
11 Correct 144 ms 8140 KB Output is correct
12 Correct 154 ms 8140 KB Output is correct
13 Correct 167 ms 8224 KB Output is correct
14 Correct 154 ms 8140 KB Output is correct
15 Correct 148 ms 8220 KB Output is correct
16 Correct 154 ms 8212 KB Output is correct
17 Correct 174 ms 8196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3023 ms 12420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8140 KB Output is correct
2 Correct 9 ms 8076 KB Output is correct
3 Correct 25 ms 8140 KB Output is correct
4 Correct 25 ms 8092 KB Output is correct
5 Correct 25 ms 8140 KB Output is correct
6 Correct 25 ms 8140 KB Output is correct
7 Correct 69 ms 8184 KB Output is correct
8 Correct 14 ms 8140 KB Output is correct
9 Correct 160 ms 8220 KB Output is correct
10 Correct 145 ms 8140 KB Output is correct
11 Correct 144 ms 8140 KB Output is correct
12 Correct 154 ms 8140 KB Output is correct
13 Correct 167 ms 8224 KB Output is correct
14 Correct 154 ms 8140 KB Output is correct
15 Correct 148 ms 8220 KB Output is correct
16 Correct 154 ms 8212 KB Output is correct
17 Correct 174 ms 8196 KB Output is correct
18 Execution timed out 3023 ms 12420 KB Time limit exceeded
19 Halted 0 ms 0 KB -