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

Compiler report

input/code.cpp: In lambda function:
input/code.cpp:61:118: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   61 |     unordered_map<int, int, function<size_t(int)>> mats(2*n, [](int val){ return hash<int>{}(val ^ 0b101111110101110 + 151618);});
      |                                                                                                    ~~~~~~~~~~~~~~~~~~^~~~~~~~

Code

#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <climits>
#include <cmath>
#include <functional>
#include <type_traits>
#include <fstream>
#include <bitset>
#include <complex>
#include <iomanip>

#include <ext/pb_ds/assoc_container.hpp> // gcc only
template<typename T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
 
#define int long long
using namespace std;
 
#define cross(x, y) (((x)*conj(y)).imag())
#define sign(v) ((0 < (v)) - ((v) < 0))



int p(int a, int b, int m)
{
    if (b == 0) return 1;
    else if (b % 2 == 0) { int r = p(a, b/2, m); return (r*r) % m; }
    else return (p(a, b-1, m)*a) % m; 
}
int gdc(int a, int b)
{
    if (b == 0) return a;
    return gdc(b, a%b);
}
 
int nCr(int n, int r, int mod)
{
    int res = 1;
    for (int i = 0; i < r; i++)
    {
        res *= (n-i);
        res *= p(i+1, mod-2, mod);
    }
    return res;
}
int mod = 998244353;

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

    unordered_map<int, int, function<size_t(int)>> mats(2*n, [](int val){ return hash<int>{}(val ^ 0b101111110101110 + 151618);});
    mats[0]++;

    int sum = 0;
    int res = 0;
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        sum += a;
        if (mats.find(sum - x) != mats.end())
            res += mats[sum - x];
        mats[sum]++;
    }

    cout << res;
}
 
 
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int t = 1;
 
    //cin >> t;
 
    for (int i = 0; i < t; i++)
    {
        solve();
        //cout.flush();
    }
}

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