CSES - COCI 2007/2008 #1 - Results
Submission details
Task:Srednji
Sender:henrikaalto
Submission time:2019-07-29 15:37:12 +0300
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.01 sdetails
#7ACCEPTED0.01 sdetails
#8ACCEPTED0.01 sdetails
#9ACCEPTED0.02 sdetails
#10ACCEPTED0.04 sdetails

Code

#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
using ii=long long;
#define F first
#define S second
int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    vector<int> d(n);
    int loc = find(all(v), x) - v.begin();
    int lol = 0;
    for (int i = loc - 1; i >= 0; --i) {
        if (v[i] > x) lol++;
        else lol--;
        d[i] = lol;
    }
    lol = 0;
    for (int i = loc + 1; i < n; ++i) {
        if (v[i] > x) lol++;
        else lol--;
        d[i] = lol;
    }
    map<int, int> m;
    for (int i = 0; i <= loc; ++i) {
        m[d[i]]++;
    }
    ii res = 0;
    for (int i = loc; i < n; ++i) {
        res += m[-d[i]];
    }
    cout << res << "\n";
}

Test details

Test 1

Verdict: ACCEPTED

input
10 6
1 3 7 10 8 6 9 4 5 2

correct output
6

user output
6

Test 2

Verdict: ACCEPTED

input
50 21
43 15 49 30 13 22 31 18 40 8 4...

correct output
57

user output
57

Test 3

Verdict: ACCEPTED

input
100 43
69 9 45 35 48 30 62 27 40 61 2...

correct output
66

user output
66

Test 4

Verdict: ACCEPTED

input
300 150
266 250 76 41 56 176 118 116 5...

correct output
4302

user output
4302

Test 5

Verdict: ACCEPTED

input
1000 469
848 616 501 850 780 759 498 48...

correct output
44308

user output
44308

Test 6

Verdict: ACCEPTED

input
3600 1447
262 2995 2479 2869 2794 2276 2...

correct output
166

user output
166

Test 7

Verdict: ACCEPTED

input
10000 5030
849 4704 1363 3835 691 3479 20...

correct output
5502889

user output
5502889

Test 8

Verdict: ACCEPTED

input
25000 12981
12814 1882 11623 7681 12837 77...

correct output
32949521

user output
32949521

Test 9

Verdict: ACCEPTED

input
55555 27897
52281 52175 41117 48827 55022 ...

correct output
626683

user output
626683

Test 10

Verdict: ACCEPTED

input
100000 53100
38451 42789 28623 42568 6499 2...

correct output
488933627

user output
488933627