Submission #53394087
Source Code Expand
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using pbds =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define cerr if(false)cerr
#define int long long
#define pb push_back
#define F first
#define S second
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define yn(x) x ? yes : no
#define f(i, s, e) for (int i = s; i < e; i++)
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int, int>
#define vpi vector<pii>
#define all(x) x.begin(), x.end()
#define minele(x) *min_element(all(x))
#define maxele(x) *max_element(all(x))
#define endl '\n'
const int N = 2e5;
const int MOD = 1e9 + 7;
const int inf = LLONG_MAX;
const int minf = -1e14;
#ifndef ONLINE_JUDGE
#define debug(x) \
cerr << (#x) << " is "; \
_print(x)
#define dbg(x...) \
cerr << (#x) << " is "; \
_print(x)
#else
#define debug(x)
#define dbg(x)
#define dbg(x...)
#endif
template <typename T>
void _print(T a)
{
cerr << a;
}
template <typename T1, typename... T2>
void _print(T1 t1, T2... t2)
{
cerr << t1 << ", ";
_print(t2...);
cerr << endl;
}
template <typename T>
void print(T a)
{
cout << a << ' ';
}
template <typename T>
void println(T a)
{
cout << a << endl;
}
template <class T>
istream &operator>>(istream &is, vector<T> &a)
{
for (auto &x : a)
is >> x;
return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a)
{
for (const auto &x : a)
os << x << ' ';
return os;
}
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p)
{
cerr << "{";
_print(p.F);
cerr << ",";
_print(p.S);
cerr << "} ";
}
template <class T>
void _print(vector<T> v)
{
cerr << "[ ";
for (T i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
cerr << endl;
}
template <class T>
void _print(set<T> v)
{
cerr << "[ ";
for (T i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
cerr << endl;
}
template <class T>
void _print(multiset<T> v)
{
cerr << "[ ";
for (T i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
cerr << endl;
}
template <class T, class V>
void _print(map<T, V> v)
{
cerr << "[ ";
for (auto i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
cerr << endl;
}
template <class T, class V>
void _print(unordered_map<T, V> v)
{
cerr << "[ ";
for (auto i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
cerr << endl;
}
void fast()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void init_code()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif // ONLINE_JUDGE
}
class SegmentTree
{
public:
int n, ret;
vi v, tree;
void build(int low, int high, int ind)
{
if (low == high)
{
tree[ind] = v[low];
return;
}
int mid = (low + high) >> 1;
build(low, mid, 2 * ind + 1);
build(mid + 1, high, 2 * ind + 2);
tree[ind] = max(tree[2 * ind + 1], tree[2 * ind + 2]);
}
SegmentTree(vi &v)
{
this->v = v;
this->n = v.size();
tree.resize(4 * n);
this->build(0, n - 1, 0);
}
void update(int low, int high, int u, int value, int ind)
{
if (low == high)
{
tree[ind] = value;
return;
}
int mid = (low + high) >> 1;
if (u <= mid)
{
update(low, mid, u, value, 2 * ind + 1);
}
else
{
update(mid + 1, high, u, value, 2 * ind + 2);
}
tree[ind] = max(tree[2 * ind + 1], tree[2 * ind + 2]);
}
int query(int low, int high, int l, int r, int ind)
{
int mid = (low + high) >> 1;
if (low > r || high < l)
{
return minf;
}
if (low >= l && high <= r)
{
return tree[ind];
}
int left = query(low, mid, l, r, 2 * ind + 1);
int right = query(mid + 1, high, l, r, 2 * ind + 2);
return max(left, right);
}
void update(int u, int x)
{
update(0, n - 1, u, x, 0);
}
int query(int l, int r)
{
return query(0, n - 1, l, r, 0);
}
};
void solve()
{
int n, c;
cin >> n >> c;
vi a(n, minf), b(n);
SegmentTree s1(a), s2(b);
s1.update(0, -c * 1);
s2.update(0, c * 1);
int m;
cin >> m;
vi dp(n + 1);
f(i, 0, m)
{
int y, p;
cin >> y >> p;
--y;
// --y;
// y > x
int left = minf, right = minf;
if(y)
left = p - (c * (y + 1)) + s2.query(0, y - 1);
// x > y
if(y != n - 1)
right = p + (c * (y + 1)) + s1.query(y + 1, n - 1);
dp[y] = max({left, right});
s1.update(y, -c * (y + 1) + dp[y]);
s2.update(y, c * (y + 1) + dp[y]);
debug(dp);
}
println(maxele(dp));
}
signed main()
{
init_code();
fast();
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}
Submission Info
Submission Time
2024-05-12 06:49:32+0900
Task
G - Merchant Takahashi
User
TheoGermal
Language
C++ 20 (gcc 12.2)
Score
0
Code Size
5927 Byte
Status
WA
Exec Time
126 ms
Memory
23572 KiB
Compile Error
Main.cpp:42: warning: "dbg" redefined
42 | #define dbg(x...)
|
Main.cpp:41: note: this is the location of the previous definition
41 | #define dbg(x)
|
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
0 / 550
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt, 01_random_65.txt, 01_random_66.txt, 01_random_67.txt, 01_random_68.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
2 ms
3468 KiB
00_sample_01.txt
AC
1 ms
3416 KiB
00_sample_02.txt
AC
1 ms
3612 KiB
00_sample_03.txt
WA
1 ms
3540 KiB
01_random_04.txt
WA
105 ms
23488 KiB
01_random_05.txt
WA
117 ms
23332 KiB
01_random_06.txt
WA
109 ms
23572 KiB
01_random_07.txt
WA
117 ms
23408 KiB
01_random_08.txt
WA
118 ms
23360 KiB
01_random_09.txt
WA
114 ms
23400 KiB
01_random_10.txt
WA
107 ms
23396 KiB
01_random_11.txt
AC
106 ms
23468 KiB
01_random_12.txt
WA
110 ms
23328 KiB
01_random_13.txt
WA
113 ms
23468 KiB
01_random_14.txt
WA
114 ms
23408 KiB
01_random_15.txt
AC
115 ms
23472 KiB
01_random_16.txt
WA
106 ms
23552 KiB
01_random_17.txt
WA
106 ms
23492 KiB
01_random_18.txt
WA
109 ms
23360 KiB
01_random_19.txt
AC
116 ms
23396 KiB
01_random_20.txt
WA
115 ms
23396 KiB
01_random_21.txt
AC
123 ms
23552 KiB
01_random_22.txt
WA
106 ms
23360 KiB
01_random_23.txt
AC
107 ms
23396 KiB
01_random_24.txt
WA
113 ms
23408 KiB
01_random_25.txt
WA
126 ms
23368 KiB
01_random_26.txt
WA
119 ms
23392 KiB
01_random_27.txt
WA
113 ms
23548 KiB
01_random_28.txt
WA
105 ms
23404 KiB
01_random_29.txt
AC
115 ms
23492 KiB
01_random_30.txt
WA
110 ms
23312 KiB
01_random_31.txt
WA
115 ms
23436 KiB
01_random_32.txt
WA
119 ms
23380 KiB
01_random_33.txt
AC
114 ms
23468 KiB
01_random_34.txt
WA
107 ms
23328 KiB
01_random_35.txt
WA
108 ms
23392 KiB
01_random_36.txt
AC
113 ms
23364 KiB
01_random_37.txt
WA
121 ms
23332 KiB
01_random_38.txt
WA
115 ms
23328 KiB
01_random_39.txt
WA
119 ms
23440 KiB
01_random_40.txt
WA
106 ms
23412 KiB
01_random_41.txt
WA
107 ms
23572 KiB
01_random_42.txt
WA
112 ms
23564 KiB
01_random_43.txt
WA
116 ms
23332 KiB
01_random_44.txt
WA
117 ms
23544 KiB
01_random_45.txt
WA
126 ms
23328 KiB
01_random_46.txt
WA
107 ms
23412 KiB
01_random_47.txt
WA
118 ms
23376 KiB
01_random_48.txt
WA
112 ms
23544 KiB
01_random_49.txt
WA
123 ms
23568 KiB
01_random_50.txt
WA
122 ms
23324 KiB
01_random_51.txt
WA
125 ms
23496 KiB
01_random_52.txt
WA
18 ms
10720 KiB
01_random_53.txt
WA
61 ms
16004 KiB
01_random_54.txt
WA
98 ms
13896 KiB
01_random_55.txt
WA
12 ms
3880 KiB
01_random_56.txt
WA
52 ms
16012 KiB
01_random_57.txt
WA
16 ms
11248 KiB
01_random_58.txt
AC
41 ms
20272 KiB
01_random_59.txt
WA
55 ms
14044 KiB
01_random_60.txt
WA
110 ms
22532 KiB
01_random_61.txt
WA
51 ms
23356 KiB
01_random_62.txt
WA
30 ms
7240 KiB
01_random_63.txt
WA
49 ms
23472 KiB
01_random_64.txt
WA
97 ms
18656 KiB
01_random_65.txt
WA
16 ms
18072 KiB
01_random_66.txt
WA
64 ms
4904 KiB
01_random_67.txt
WA
19 ms
3544 KiB
01_random_68.txt
WA
19 ms
3616 KiB