#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define FORD(i,a,b) for (int i = (a), _b = (b); i >= (_b); --i)
#define getBit(mask,i) (((mask) >> (i)) & (1LL))
#define MASK(x) (1LL << (x))
#define allof(x) begin(x), end(x)
#define el cout << '\n';
//--Compare------------------------------------------------------------------------------------
template<class X, class Y>
inline bool maximize(X &x, const Y &y){ return (x < y) ? x = y, 1 : 0; }
template<class X, class Y>
inline bool minimize(X &x, const Y &y){ return (x > y) ? x = y, 1 : 0; }
//--Process------------------------------------------------------------------------------------
#define int long long
struct DynamicSegmentTree
{
struct Node
{
int left, right, sum, lazy;
Node()
{
left = right = lazy = -1;
sum = 0;
}
};
int cntNodes;
vector <Node> Nodes;
DynamicSegmentTree(int n, int q = 0)
{
if (q) Nodes.reserve(2 * q * __lg(n));
Nodes = vector <Node> (1);
cntNodes = 1;
}
void apply(int id, int l, int r, int val)
{
if (val == -1) return;
Nodes[id].lazy = val;
Nodes[id].sum = 1LL * (r - l + 1) * val;
}
void down(int id, int l, int r)
{
if (Nodes[id].left == -1)
{
Nodes[id].left = cntNodes++;
Nodes.emplace_back(Node());
}
if (Nodes[id].right == -1)
{
Nodes[id].right = cntNodes++;
Nodes.emplace_back(Node());
}
int mid = (l + r) >> 1LL;
apply(Nodes[id].left, l, mid, Nodes[id].lazy);
apply(Nodes[id].right, mid + 1, r, Nodes[id].lazy);
Nodes[id].lazy = -1;
}
void update(int u, int v, int val, int l, int r, int id)
{
if (v < l || r < u) return;
if (u <= l && r <= v)
{
apply(id, l, r, val);
return;
}
down(id, l, r);
int mid = (l + r) >> 1LL;
int lc = Nodes[id].left, rc = Nodes[id].right;
update(u, v, val, l, mid, lc);
update(u, v, val, mid + 1, r, rc);
Nodes[id].sum = Nodes[lc].sum + Nodes[rc].sum;
}
int get(int u, int v, int l, int r, int id)
{
if (v < l || r < u) return 0;
if (u <= l && r <= v) return Nodes[id].sum;
down(id, l, r);
int mid = (l + r) >> 1LL;
return get(u, v, l, mid, Nodes[id].left) + get(u, v, mid + 1, r, Nodes[id].right);
}
} ;
signed main(void)
{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define task "f"
if (fopen(task".INP", "r"))
{
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
//--OpenFile-------------------------------------------------------------------------------
int q; cin >> q;
int C = 0;
DynamicSegmentTree IT(1e9 + 1, q);
while (q--)
{
int cmd, l, r; cin >> cmd >> l >> r;
if (cmd == 1)
{
C = IT.get(l + C, r + C, 1, 1e9, 0);
cout << C << '\n';
}
else
{
IT.update(l + C, r + C, 1, 1, 1e9, 0);
}
}
cerr << (1.0 * clock() / CLOCKS_PER_SEC);
return 0;
}
Compilation message (stderr)
apple.cpp: In function 'int main()':
apple.cpp:110:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:111:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
111 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |