CSES - Aalto Competitive Programming 2024 - wk12 Homework - Results
Submission details
Task:Subarray Sums II
Sender:AleksandrPolitov
Submission time:2024-11-23 08:35:23 +0200
Language:C++ (C++20)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.15 sdetails
#6ACCEPTED0.13 sdetails
#7ACCEPTED0.03 sdetails
#8ACCEPTED0.06 sdetails
#9ACCEPTED0.08 sdetails
#10ACCEPTED0.08 sdetails
#11ACCEPTED0.08 sdetails
#12ACCEPTED0.13 sdetails
#13ACCEPTED0.16 sdetails
#14ACCEPTED0.16 sdetails
#15ACCEPTED0.17 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.01 sdetails
#18ACCEPTED0.08 sdetails
#19ACCEPTED0.14 sdetails
#20ACCEPTED0.07 sdetails
#21ACCEPTED0.12 sdetails
#22ACCEPTED0.16 sdetails
#23ACCEPTED0.16 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.12 sdetails
#26ACCEPTED0.11 sdetails
#27ACCEPTED0.08 sdetails
#28ACCEPTED0.13 sdetails

Code

#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define char unsigned char
#define rep(i, a, b) for(int i=a; i< (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back

#define LSOne(S) ((S) & -(S))

using namespace std;
// mt19937 rnd(239);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> int sgn(T x) { return (T(0) < x) - (x < T(0)); }
typedef long double T;
typedef complex<T> pt;
#define X real()
#define Y imag()

template<class T>
istream& operator>> (istream& is, complex<T>& p) {
    T value;
    is >> value;
    p.real(value);
    is >> value;
    p.imag(value);
    return is;
}

typedef long long ll;
typedef long double ld;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif

template<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;}
template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;}

const int INF = 1e9; // 10^9 = 1B is < 2^31-1
const ll LLINF = 4e18; // 4*10^18 is < 2^63-1
const double EPS = 1e-9;
const ll MOD = 1e9+7;

int solve() {
    ll n, x; std::cin >> n >> x;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
    }

    ll res=0;
    ll curr=0;
    std::map<ll, ll> mp;
    mp[0]=1;
    for (int i = 0; i < n; i++) {
        curr+=v[i];
        res+=mp[-(x-curr)];
        mp[curr]++;
    }

    std::cout << res << std::endl;

    
    return 0;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1;
    //cin >> TET;
    for (int i = 1; i <= TET; i++) {
        #ifdef ONPC
            cout << "TEST CASE#" << i << endl;
        #endif
        
        if (solve()) {
            break;
        }

        #ifdef ONPC
            cout << "__________________________" << endl;
        #endif
    }
    #ifdef ONPC
        cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
}

Test details

Test 1

Verdict: ACCEPTED

input
100 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
51

user output
51

Test 2

Verdict: ACCEPTED

input
100 1000000000
1000000000 1000000000 10000000...

correct output
100

user output
100

Test 3

Verdict: ACCEPTED

input
100 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
5050

user output
5050

Test 4

Verdict: ACCEPTED

input
100 4
2 1 -3 2 -7 7 -2 6 9 -4 10 -6 ...

correct output
53

user output
53

Test 5

Verdict: ACCEPTED

input
200000 100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
100001

user output
100001

Test 6

Verdict: ACCEPTED

input
200000 1000000000
1000000000 1000000000 10000000...

correct output
200000

user output
200000

Test 7

Verdict: ACCEPTED

input
200000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
20000100000

user output
20000100000

Test 8

Verdict: ACCEPTED

input
200000 39
44 -62 -3 23 11 -68 42 69 -22 ...

correct output
903601

user output
903601

Test 9

Verdict: ACCEPTED

input
131072 199999
199999 199999 199999 199999 19...

correct output
131072

user output
131072

Test 10

Verdict: ACCEPTED

input
131072 107897
107897 107897 107897 107897 10...

correct output
131072

user output
131072

Test 11

Verdict: ACCEPTED

input
131072 126271
126271 126271 126271 126271 12...

correct output
131072

user output
131072

Test 12

Verdict: ACCEPTED

input
200000 107897
107897 107897 107897 107897 10...

correct output
199999

user output
199999

Test 13

Verdict: ACCEPTED

input
200000 100000
1056323 1056323 1056323 105632...

correct output
0

user output
0

Test 14

Verdict: ACCEPTED

input
200000 100000
2144977 2144977 2144977 214497...

correct output
0

user output
0

Test 15

Verdict: ACCEPTED

input
200000 100000
65536 65536 65536 65536 65536 ...

correct output
0

user output
0

Test 16

Verdict: ACCEPTED

input
5 0
0 0 0 0 0

correct output
15

user output
15

Test 17

Verdict: ACCEPTED

input
20 536870912
268435456 268435456 268435456 ...

correct output
19

user output
19

Test 18

Verdict: ACCEPTED

input
131072 136607
136607 136607 136607 136607 13...

correct output
131072

user output
131072

Test 19

Verdict: ACCEPTED

input
200000 562841
562841 562841 562841 562841 56...

correct output
200000

user output
200000

Test 20

Verdict: ACCEPTED

input
107897 107897
107897 107897 107897 107897 10...

correct output
107897

user output
107897

Test 21

Verdict: ACCEPTED

input
200000 202409
101204 101205 101204 101205 10...

correct output
199998

user output
199998

Test 22

Verdict: ACCEPTED

input
200000 202409
138630 138631 138630 138631 13...

correct output
0

user output
0

Test 23

Verdict: ACCEPTED

input
200000 10273
410857 410857 410857 410857 41...

correct output
0

user output
0

Test 24

Verdict: ACCEPTED

input
5 2
1 -1 1 -1 2

correct output
3

user output
3

Test 25

Verdict: ACCEPTED

input
200000 1
1048577 -1048570 29 145 725 36...

correct output
104671

user output
104671

Test 26

Verdict: ACCEPTED

input
200000 1
1048577 -1048571 25 125 625 31...

correct output
104859

user output
104859

Test 27

Verdict: ACCEPTED

input
200000 0
5334500 -3502392 3421268 -2064...

correct output
6341575890

user output
6341575890

Test 28

Verdict: ACCEPTED

input
200000 0
172933 172933 172933 172933 17...

correct output
0

user output
0