#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define scld(t) scanf("%ld", &t)
#define sclld(t) scanf("%lld", &t)
#define scc(t) scanf("%c", &t)
#define scs(t) scanf("%s", t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long int li;
typedef unsigned long int uli;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
struct dat
{
lli val = 0;
lli lzst = 0;
};
vector<dat> seg;
void recalculate(int x)
{
seg[x].val = seg[2 * x + 1].val + seg[2 * x + 2].val;
}
void pushdown(int x, int l, int mid, int r)
{
int lc = 2 * x + 1;
int rc = 2 * x + 2;
if (seg[x].lzst)
{
seg[lc].lzst = seg[x].lzst;
seg[rc].lzst = seg[x].lzst;
seg[lc].val = (mid - l + 1) * seg[lc].lzst;
seg[rc].val = (r - mid) * seg[rc].lzst;
seg[x].lzst = 0;
}
}
void setval(int x, int l, int r, int lx, int rx, lli v)
{
if (r < lx || l > rx)
{
return;
}
if (lx <= l && r <= rx)
{
seg[x].val = (r - l + 1) * v;
seg[x].lzst = v;
return;
}
int mid = (l + r) / 2;
pushdown(x, l, mid, r);
setval(2 * x + 1, l, mid, lx, rx, v);
setval(2 * x + 2, mid + 1, r, lx, rx, v);
recalculate(x);
}
lli query(int x, int l, int r, int lx, int rx)
{
if (r < lx || l > rx)
{
return 0;
}
if (lx <= l && r <= rx)
{
return seg[x].val;
}
int mid = (l + r) / 2;
pushdown(x, l, mid, r);
return query(2 * x + 1, l, mid, lx, rx) + query(2 * x + 2, mid + 1, r, lx, rx);
}
int main()
{
int n, q;
n = 1e7;
scd(q);
int sze = 1;
while (sze < n)
sze *= 2;
seg = vector<dat>(2 * sze);
lli c = 0;
frange(_, q)
{
int typ;
scd(typ);
int l, r;
scd(l);
scd(r);
l--;
r--;
l += c;
r += c;
if (typ == 1)
{
lli out = query(0, 0, sze - 1, l, r);
c += out;
printf("%lld\n", out);
}
else if (typ == 2)
{
setval(0, 0, sze - 1, l, r, 1);
}
}
}
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
apple.cpp:100:5: note: in expansion of macro 'scd'
100 | scd(q);
| ^~~
apple.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
apple.cpp:109:9: note: in expansion of macro 'scd'
109 | scd(typ);
| ^~~
apple.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
apple.cpp:111:9: note: in expansion of macro 'scd'
111 | scd(l);
| ^~~
apple.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
apple.cpp:112:9: note: in expansion of macro 'scd'
112 | scd(r);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
104 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |