Submission #74718230
Source Code Expand
#include<bits/extc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx,avx2")
#include<iostream>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define mp make_pair
// #define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
// #define cin fin
// #define cout fout
// ifstream fin("word.in");
// ofstream fout("word.out");
const int inf = INT_MAX;
const int MOD = 1000000007;
double PI = 4*atan(1);
#ifdef DEBUG
string to_string(char c) { return string({c}); }
// 7
template<class... Ts>
ostream& operator<<(ostream& o, tuple<Ts...> t) {
string s = "(";
apply([&](auto&&... r) {
((s += to_string(r) + ", "), ...); }, t);
return o << s.substr(0, len(s) - 2) + ")";
}
// 3
ostream& operator<<(ostream &o, pair<auto, auto> p) {
return o << "(" << p.fi << ", " << p.se << ")";
}
// 7
template<class C, class T = typename C::value_type,
typename std::enable_if<!std::is_same<C, std::string>
::value>::type* = nullptr>
ostream& operator<<(ostream &o, C c) {
for (auto e : c) o << setw(7) << right << e;
return o << endc << endl << coutc;
}
// 7
void debug(const auto &e, const auto &... r) {
cout << coutc << e;
((cout << " " << r), ..., (cout << endc << endl));
}
#else
#define debug(...)
#endif
map<string,int> mon;
map<int,string> inp;
struct stt {
int p, len, base;
};
int n, m, lg;
vi a, ns;
vector<vi> up;
void build_ns() {
ns.assign(n, n);
vi st;
st.reserve(n);
int i = n - 1;
while (i >= 0) {
while (!st.empty() && a[st.back()] >= a[i]) st.pop_back();
if (!st.empty()) ns[i] = st.back();
st.push_back(i);
i--;
}
lg = 1;
while ((1 << lg) <= n) lg++;
up.assign(lg, vi(n + 1, n));
i = 0;
while (i < n) {
up[0][i] = ns[i];
i++;
}
up[0][n] = n;
int j = 1;
while (j < lg) {
i = 0;
while (i <= n) {
up[j][i] = up[j - 1][up[j - 1][i]];
i++;
}
j++;
}
}
int getf(int p, int len) {
if (p >= n) return n;
if (a[p] < len) return p;
int u = p;
int j = lg - 1;
while (j >= 0) {
int v = up[j][u];
if (v < n && a[v] >= len) u = v;
j--;
}
return ns[u];
}
void xr(ll &ans, int l, int r, int v) {
if (l > r || v == 0) return;
int k = l;
while (k <= r) {
ans ^= 1LL*k*v;
k++;
}
}
void _main(int tc) {
cin >> n >> m;
a.assign(n, 0);
int i = 0;
while (i < n) cin >> a[i], i++;
build_ns();
ll ans = 0;
vector<stt> st;
st.reserve(4*n + 100);
st.push_back({0, m + 1, 0});
while (!st.empty()) {
stt cur = st.back();
st.pop_back();
int p = cur.p, len = cur.len, base = cur.base;
int j = getf(p, len);
if (j == n) {
int l = max(1, base);
int r = min(m, base + len - 1);
xr(ans, l, r, base);
continue;
}
int x = a[j];
st.push_back({j + 1, len - x, base + x});
st.push_back({j + 1, x, base});
}
cout << ans << endl;
}
// 5
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int tc; cin >> tc; rep(i, tc) _main(i + 1);
}
Submission Info
| Submission Time |
|
| Task |
D - Greedy Customer |
| User |
zaahir |
| Language |
C++23 (GCC 15.2.0) |
| Score |
0 |
| Code Size |
4356 Byte |
| Status |
TLE |
| Exec Time |
> 2000 ms |
| Memory |
50304 KiB |
Compile Error
./Main.cpp: In function 'void _main(int)':
./Main.cpp:157:16: warning: unused parameter 'tc' [-Wunused-parameter]
157 | void _main(int tc) {
| ~~~~^~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 700 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt |
| All |
00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 01_handmade_16.txt, 01_handmade_17.txt, 01_handmade_18.txt, 01_handmade_19.txt, 01_handmade_20.txt, 01_handmade_21.txt, 01_handmade_22.txt, 01_handmade_23.txt, 01_handmade_24.txt, 01_handmade_25.txt, 01_handmade_26.txt, 01_handmade_27.txt, 01_handmade_28.txt, 01_handmade_29.txt, 01_handmade_30.txt, 01_handmade_31.txt, 01_handmade_32.txt, 01_handmade_33.txt, 01_handmade_34.txt, 01_handmade_35.txt, 01_handmade_36.txt, 01_handmade_37.txt, 01_handmade_38.txt, 01_handmade_39.txt, 01_handmade_40.txt, 01_handmade_41.txt, 01_handmade_42.txt, 01_handmade_43.txt, 01_handmade_44.txt, 01_handmade_45.txt, 01_handmade_46.txt, 01_handmade_47.txt, 01_handmade_48.txt, 01_handmade_49.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3460 KiB |
| 01_handmade_00.txt |
AC |
43 ms |
46324 KiB |
| 01_handmade_01.txt |
AC |
38 ms |
46324 KiB |
| 01_handmade_02.txt |
AC |
5 ms |
4232 KiB |
| 01_handmade_03.txt |
TLE |
> 2000 ms |
4192 KiB |
| 01_handmade_04.txt |
AC |
1 ms |
3416 KiB |
| 01_handmade_05.txt |
AC |
810 ms |
46432 KiB |
| 01_handmade_06.txt |
AC |
550 ms |
46452 KiB |
| 01_handmade_07.txt |
AC |
48 ms |
46328 KiB |
| 01_handmade_08.txt |
AC |
53 ms |
46448 KiB |
| 01_handmade_09.txt |
AC |
79 ms |
46424 KiB |
| 01_handmade_10.txt |
AC |
45 ms |
46328 KiB |
| 01_handmade_11.txt |
AC |
1288 ms |
46376 KiB |
| 01_handmade_12.txt |
AC |
5 ms |
4376 KiB |
| 01_handmade_13.txt |
TLE |
> 2000 ms |
4064 KiB |
| 01_handmade_14.txt |
AC |
42 ms |
46432 KiB |
| 01_handmade_15.txt |
TLE |
> 2000 ms |
50120 KiB |
| 01_handmade_16.txt |
AC |
869 ms |
46452 KiB |
| 01_handmade_17.txt |
AC |
823 ms |
46328 KiB |
| 01_handmade_18.txt |
AC |
584 ms |
46452 KiB |
| 01_handmade_19.txt |
AC |
851 ms |
46484 KiB |
| 01_handmade_20.txt |
TLE |
> 2000 ms |
50144 KiB |
| 01_handmade_21.txt |
TLE |
> 2000 ms |
50088 KiB |
| 01_handmade_22.txt |
TLE |
> 2000 ms |
50120 KiB |
| 01_handmade_23.txt |
TLE |
> 2000 ms |
50304 KiB |
| 01_handmade_24.txt |
AC |
868 ms |
46328 KiB |
| 01_handmade_25.txt |
AC |
1894 ms |
46380 KiB |
| 01_handmade_26.txt |
AC |
1896 ms |
46372 KiB |
| 01_handmade_27.txt |
TLE |
> 2000 ms |
46432 KiB |
| 01_handmade_28.txt |
AC |
142 ms |
46328 KiB |
| 01_handmade_29.txt |
TLE |
> 2000 ms |
46484 KiB |
| 01_handmade_30.txt |
TLE |
> 2000 ms |
46380 KiB |
| 01_handmade_31.txt |
TLE |
> 2000 ms |
46432 KiB |
| 01_handmade_32.txt |
TLE |
> 2000 ms |
46376 KiB |
| 01_handmade_33.txt |
TLE |
> 2000 ms |
46452 KiB |
| 01_handmade_34.txt |
TLE |
> 2000 ms |
46288 KiB |
| 01_handmade_35.txt |
TLE |
> 2000 ms |
46328 KiB |
| 01_handmade_36.txt |
TLE |
> 2000 ms |
46432 KiB |
| 01_handmade_37.txt |
TLE |
> 2000 ms |
46432 KiB |
| 01_handmade_38.txt |
TLE |
> 2000 ms |
46324 KiB |
| 01_handmade_39.txt |
TLE |
> 2000 ms |
46380 KiB |
| 01_handmade_40.txt |
TLE |
> 2000 ms |
46328 KiB |
| 01_handmade_41.txt |
TLE |
> 2000 ms |
46452 KiB |
| 01_handmade_42.txt |
TLE |
> 2000 ms |
46760 KiB |
| 01_handmade_43.txt |
TLE |
> 2000 ms |
46328 KiB |
| 01_handmade_44.txt |
TLE |
> 2000 ms |
46448 KiB |
| 01_handmade_45.txt |
TLE |
> 2000 ms |
46484 KiB |
| 01_handmade_46.txt |
AC |
1283 ms |
46432 KiB |
| 01_handmade_47.txt |
AC |
864 ms |
46312 KiB |
| 01_handmade_48.txt |
AC |
1893 ms |
46312 KiB |
| 01_handmade_49.txt |
AC |
1317 ms |
46380 KiB |
| 02_random_00.txt |
AC |
25 ms |
8792 KiB |
| 02_random_01.txt |
AC |
29 ms |
7476 KiB |
| 02_random_02.txt |
AC |
31 ms |
7456 KiB |
| 02_random_03.txt |
AC |
22 ms |
7200 KiB |
| 02_random_04.txt |
AC |
26 ms |
17640 KiB |
| 02_random_05.txt |
AC |
19 ms |
14440 KiB |
| 02_random_06.txt |
AC |
19 ms |
15428 KiB |
| 02_random_07.txt |
AC |
15 ms |
12404 KiB |
| 02_random_08.txt |
AC |
66 ms |
43764 KiB |
| 02_random_09.txt |
AC |
19 ms |
15780 KiB |
| 02_random_10.txt |
AC |
32 ms |
18784 KiB |
| 02_random_11.txt |
AC |
37 ms |
26900 KiB |
| 02_random_12.txt |
AC |
43 ms |
39264 KiB |
| 02_random_13.txt |
AC |
6 ms |
4628 KiB |
| 02_random_14.txt |
AC |
64 ms |
33964 KiB |
| 02_random_15.txt |
AC |
436 ms |
18804 KiB |
| 02_random_16.txt |
TLE |
> 2000 ms |
26328 KiB |
| 02_random_17.txt |
TLE |
> 2000 ms |
32760 KiB |
| 02_random_18.txt |
AC |
28 ms |
17504 KiB |
| 02_random_19.txt |
AC |
41 ms |
24024 KiB |
| 02_random_20.txt |
AC |
56 ms |
46292 KiB |
| 02_random_21.txt |
AC |
88 ms |
46304 KiB |
| 02_random_22.txt |
AC |
80 ms |
46432 KiB |
| 02_random_23.txt |
AC |
68 ms |
46304 KiB |
| 02_random_24.txt |
AC |
1863 ms |
46448 KiB |
| 02_random_25.txt |
AC |
1709 ms |
11232 KiB |
| 02_random_26.txt |
AC |
1664 ms |
7080 KiB |
| 02_random_27.txt |
AC |
1867 ms |
46304 KiB |
| 02_random_28.txt |
AC |
1867 ms |
46304 KiB |
| 02_random_29.txt |
AC |
1867 ms |
46432 KiB |