#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (auto i=(a); i<(b); i++)
#define FORD(i, a, b) for (auto i=(a); i>(b); i--)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m)>>(i) & 1)
#define ft first
#define sd second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree <T, null_type, std::less<T>, rb_tree_tag,
tree_order_statistics_node_update>; //find_by_order() / order_of_key()
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = std::min(a, (T1)b); }
template <typename T1, typename T2> inline void remax(T1& a, T2 b) { a = std::max(a, (T1)b); }
const int maxN = 1 << 20;
long long W[maxN];
int n, A[maxN];
void nz(int q)
{
while (q--)
{
int ev, a, b;
scanf ("%d%d%d", &ev, &a, &b);
if (ev == 1)
W[a] += b;
else
{
long long res = 0, w = 0;
FORD(i, n, 0)
{
w += W[i];
if (i <= a and b <= A[i])
res += w;
}
printf("%lld\n", res);
}
}
}
std::vector <std::pair <int, int> > Upds; // day, w
std::vector <std::pair <int, int> > Q; // day, updsCnt
std::vector <int> qInds[maxN], treeDays[maxN];
ordered_set <int> activeDays;
long long res[maxN];
int getDayOrder(int d)
{
return activeDays.order_of_key(++d);
}
void mz(int q)
{
FOR(_, 0, q)
{
int ev, a, b;
scanf ("%d%d%d", &ev, &a, &b);
if (ev == 1)
Upds.push_back({ a, b });
else
{
qInds[b].push_back(SZ(Q));
Q.push_back({ a, SZ(Upds) });
}
}
activeDays.insert(maxN);
FORD(a, maxN-1, 0)
{
for (int d : treeDays[a])
activeDays.insert(d);
for (int qi : qInds[a])
{
auto [qDay, upds] = Q[qi];
int allDays = getDayOrder(qDay);
FOR(ui, 0, upds)
{
auto [uDay, w] = Upds[ui];
int d = uDay >= qDay ? allDays : getDayOrder(uDay);
res[qi] += 1ll * w * d;
}
}
}
FOR(i, 0, SZ(Q))
printf("%lld\n", res[i]);
}
void solve()
{
int m, z;
scanf ("%d%d%d", &n, &m, &z);
FOR(i, 1, n+1)
scanf ("%d", A+i), treeDays[A[i]].push_back(i);
if (1ll * n * z <= 200'000'000)
nz(m + z);
else
mz(m + z);
}
int main()
{
int tc = 1;
// scanf ("%d", &tc);
FOR(cid, 1, tc+1)
solve();
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #pragma GCC optimize ("Ofast") #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define FOR(i, a, b) for (auto i=(a); i<(b); i++) #define FORD(i, a, b) for (auto i=(a); i>(b); i--) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define ithBit(m, i) ((m)>>(i) & 1) #define ft first #define sd second #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree <T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>; //find_by_order() / order_of_key() #ifdef DEBUG #include "debug.h" #else #define dbg(...) 0 #endif template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = std::min(a, (T1)b); } template <typename T1, typename T2> inline void remax(T1& a, T2 b) { a = std::max(a, (T1)b); } const int maxN = 1 << 20; long long W[maxN]; int n, A[maxN]; void nz(int q) { while (q--) { int ev, a, b; scanf ("%d%d%d", &ev, &a, &b); if (ev == 1) W[a] += b; else { long long res = 0, w = 0; FORD(i, n, 0) { w += W[i]; if (i <= a and b <= A[i]) res += w; } printf("%lld\n", res); } } } std::vector <std::pair <int, int> > Upds; // day, w std::vector <std::pair <int, int> > Q; // day, updsCnt std::vector <int> qInds[maxN], treeDays[maxN]; ordered_set <int> activeDays; long long res[maxN]; int getDayOrder(int d) { return activeDays.order_of_key(++d); } void mz(int q) { FOR(_, 0, q) { int ev, a, b; scanf ("%d%d%d", &ev, &a, &b); if (ev == 1) Upds.push_back({ a, b }); else { qInds[b].push_back(SZ(Q)); Q.push_back({ a, SZ(Upds) }); } } activeDays.insert(maxN); FORD(a, maxN-1, 0) { for (int d : treeDays[a]) activeDays.insert(d); for (int qi : qInds[a]) { auto [qDay, upds] = Q[qi]; int allDays = getDayOrder(qDay); FOR(ui, 0, upds) { auto [uDay, w] = Upds[ui]; int d = uDay >= qDay ? allDays : getDayOrder(uDay); res[qi] += 1ll * w * d; } } } FOR(i, 0, SZ(Q)) printf("%lld\n", res[i]); } void solve() { int m, z; scanf ("%d%d%d", &n, &m, &z); FOR(i, 1, n+1) scanf ("%d", A+i), treeDays[A[i]].push_back(i); if (1ll * n * z <= 200'000'000) nz(m + z); else mz(m + z); } int main() { int tc = 1; // scanf ("%d", &tc); FOR(cid, 1, tc+1) solve(); return 0; } |
English