Submission #68941365
Source Code Expand
#line 1 "main.cpp"
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vul = vector<ull>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vs = vector<string>;
template<class T> using pq = priority_queue<T,vector<T>, greater<T>>;
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(a,b,c,name,...) name
#define rep1(n) for (ll UNUSED_NUMBER = 0; UNUSED_NUMBER < (n); ++UNUSED_NUMBER)
#define rep2(i, n) for (ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n) - 1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n) - 1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (b) - 1;i >= (a);i--)
#define rrep4(i,a,b,c) for(ll i = (a) + (((b)-(a)-1) / (c) - (((b)-(a)-1) % (c) && (((b)-(a)-1) ^ c) < 0)) * (c);i >= (a);i -= c)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define all1(i) begin(i) , end(i)
#define all2(i,a) begin(i) , begin(i) + a
#define all3(i,a,b) begin(i) + a , begin(i) + b
#define all(...) overload3(__VA_ARGS__, all3, all2, all1)(__VA_ARGS__)
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){return *min_element(all(a));}
template<class T> auto max(const T& a){return *max_element(all(a));}
template<class... Ts> void in(Ts&... t);
#define INT(...) int __VA_ARGS__; in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__; in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; in(__VA_ARGS__)
#define VEC(type, name, size) vector<type> name(size); in(name)
#define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); in(name)
ll intpow(ll a, ll b){ll ans = 1; while(b){if(b & 1) ans *= a; a *= a; b /= 2;} return ans;}
ll modpow(ll a, ll b, ll p){ ll ans = 1; a %= p;if(a < 0) a += p;while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
bool is_clamp(ll val,ll low,ll high) {return low <= val && val < high;}
void Yes() {cout << "Yes\n";return;}
void No() {cout << "No\n";return;}
void YES() {cout << "YES\n";return;}
void NO() {cout << "NO\n";return;}
template <typename T>
T floor(T a, T b) {return a / b - (a % b && (a ^ b) < 0);}
template <typename T>
T ceil(T x, T y) {return floor(x + y - 1, y);}
template <typename T>
T bmod(T x, T y) {return x - y * floor(x, y);}
template <typename T>
pair<T, T> divmod(T x, T y) {T q = floor(x, y);return {q, x - q * y};}
namespace IO{
#define VOID(a) decltype(void(a))
struct setting{ setting(){cin.tie(nullptr); ios::sync_with_stdio(false);fixed(cout); cout.precision(15);}} setting;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){in(get<idx>(t)...);}
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ituple(t, make_index_sequence<tuple_size<T>::value>{});}
#undef VOID
}
#define unpack(a) (void)initializer_list<int>{(a, 0)...}
template<class... Ts> void in(Ts&... t){ unpack(IO :: i(t)); }
#undef unpack
constexpr long double PI = 3.141592653589793238462643383279L;
template <class F> struct REC {
F f;
REC(F &&f_) : f(forward<F>(f_)) {}
template <class... Args> auto operator()(Args &&...args) const { return f(*this, forward<Args>(args)...); }};
constexpr int mod = 998244353;
//constexpr int mod = 1000000007
#line 2 "library/segtree/lazysegtree.hpp"
template <class S,
S (*op)(S, S),
S (*e)(),
class F,
S (*mapping)(F, S),
F (*composition)(F, F),
F (*id)()>
struct lazy_segtree {
public:
lazy_segtree() : lazy_segtree(0) {}
explicit lazy_segtree(int n) : lazy_segtree(vector<S>(n, e())) {}
explicit lazy_segtree(const vector<S>& v) : _n(int(v.size())) {
log = 0;
while ((1U << log) < (unsigned int)(_n)) log++;
size = 1 << log;
d = vector<S>(2 * size, e());
lz = vector<F>(size, id());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return d[p];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return e();
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
S sml = e(), smr = e();
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() { return d[1]; }
void apply(int p, F f) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = mapping(f, d[p]);
for (int i = 1; i <= log; i++) update(p >> i);
}
void apply(int l, int r, F f) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return;
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
{
int l2 = l, r2 = r;
while (l < r) {
if (l & 1) all_apply(l++, f);
if (r & 1) all_apply(--r, f);
l >>= 1;
r >>= 1;
}
l = l2;
r = r2;
}
for (int i = 1; i <= log; i++) {
if (((l >> i) << i) != l) update(l >> i);
if (((r >> i) << i) != r) update((r - 1) >> i);
}
}
template <bool (*g)(S)> int max_right(int l) {
return max_right(l, [](S x) { return g(x); });
}
template <class G> int max_right(int l, G g) {
assert(0 <= l && l <= _n);
assert(g(e()));
if (l == _n) return _n;
l += size;
for (int i = log; i >= 1; i--) push(l >> i);
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!g(op(sm, d[l]))) {
while (l < size) {
push(l);
l = (2 * l);
if (g(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*g)(S)> int min_left(int r) {
return min_left(r, [](S x) { return g(x); });
}
template <class G> int min_left(int r, G g) {
assert(0 <= r && r <= _n);
assert(g(e()));
if (r == 0) return 0;
r += size;
for (int i = log; i >= 1; i--) push((r - 1) >> i);
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!g(op(d[r], sm))) {
while (r < size) {
push(r);
r = (2 * r + 1);
if (g(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
vector<S> d;
vector<F> lz;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
void all_apply(int k, F f) {
d[k] = mapping(f, d[k]);
if (k < size) lz[k] = composition(f, lz[k]);
}
void push(int k) {
all_apply(2 * k, lz[k]);
all_apply(2 * k + 1, lz[k]);
lz[k] = id();
}
};
#line 100 "main.cpp"
struct S {
ll val;int size;
};
const ll LINF = 0x1fffffffffffffff;
S op(S x,S y) {return S{x.val + y.val,x.size + y.size};}
S e() {return S{0,1};}
S mapping(ll f,S x) {
if (f == LINF) return x;
return S{f*x.size,x.size};
}
ll composition (ll L,ll R) {
if (L == LINF) return R;
return L;
}
ll id() {return LINF;}
void solve() {
INT(q);
vi pre(q+1,-1);
vi aft(q+1,-1);
vvi query(q);
rep(i,q) {
INT(cmd);
if(cmd == 1) {
INT(x);
query[i] = {1,x};
int aftx = aft[x];
pre[i+1] = x;
aft[x] = i + 1;
if(aftx != -1) {
pre[aftx] = i + 1;
aft[i+1] = aftx;
}
}
else {
INT(x,y);
query[i] = {2,x,y};
}
}
vi V;
int now = 0;
while(now != -1) {
V.emplace_back(now);
now = aft[now];
}
vi ids(q+1);
rep(i,V.size()) ids[V[i]] = i;
vector<S> init(V.size());
rep(i,V.size()) init[i] = {0,1};
lazy_segtree<S,op,e,ll,mapping,composition,id> seg(init);
rep(i,q) {
if(query[i][0] == 1) {
seg.set(ids[i+1],{i+1,1});
}
else {
int x = query[i][1];
int y = query[i][2];
int id1 = ids[x];
int id2 = ids[y];
if(id1 > id2) swap(id1,id2);
ll ans = seg.prod(id1+1,id2).val;
seg.apply(id1+1,id2,0);
cout << ans << '\n';
}
}
}
int main() {
//INT(TT);
int TT = 1;
rep(i,TT) solve();
}
Submission Info
Submission Time
2025-08-30 22:28:03+0900
Task
F - Erase between X and Y
User
siganai
Language
C++ 20 (gcc 12.2)
Score
525
Code Size
10930 Byte
Status
AC
Exec Time
221 ms
Memory
66860 KiB
Compile Error
main.cpp: In function ‘void solve()’:
main.cpp:32:37: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
main.cpp:29:46: note: in expansion of macro ‘rep2’
main.cpp:35:18: note: in expansion of macro ‘overload4’
main.cpp:146:5: note: in expansion of macro ‘rep’
main.cpp:32:37: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
main.cpp:29:46: note: in expansion of macro ‘rep2’
main.cpp:35:18: note: in expansion of macro ‘overload4’
main.cpp:148:5: note: in expansion of macro ‘rep’
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
525 / 525
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_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, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
1 ms
3452 KiB
00_sample_01.txt
AC
1 ms
3388 KiB
00_sample_02.txt
AC
1 ms
3520 KiB
01_random_00.txt
AC
81 ms
36276 KiB
01_random_01.txt
AC
206 ms
38084 KiB
01_random_02.txt
AC
217 ms
39984 KiB
01_random_03.txt
AC
221 ms
43032 KiB
01_random_04.txt
AC
217 ms
43592 KiB
01_random_05.txt
AC
212 ms
44076 KiB
01_random_06.txt
AC
215 ms
49568 KiB
01_random_07.txt
AC
211 ms
50168 KiB
01_random_08.txt
AC
204 ms
50672 KiB
01_random_09.txt
AC
198 ms
51216 KiB
01_random_10.txt
AC
191 ms
51388 KiB
01_random_11.txt
AC
192 ms
62280 KiB
01_random_12.txt
AC
186 ms
62896 KiB
01_random_13.txt
AC
177 ms
63296 KiB
01_random_14.txt
AC
169 ms
63932 KiB
01_random_15.txt
AC
160 ms
64124 KiB
01_random_16.txt
AC
152 ms
64652 KiB
01_random_17.txt
AC
143 ms
65268 KiB
01_random_18.txt
AC
134 ms
65872 KiB
01_random_19.txt
AC
126 ms
66228 KiB
01_random_20.txt
AC
182 ms
66748 KiB
02_random2_00.txt
AC
152 ms
64120 KiB
02_random2_01.txt
AC
134 ms
65176 KiB
02_random2_02.txt
AC
127 ms
65624 KiB
02_random2_03.txt
AC
119 ms
66244 KiB
02_random2_04.txt
AC
115 ms
66568 KiB
03_handmade_00.txt
AC
1 ms
3448 KiB
03_handmade_01.txt
AC
113 ms
66836 KiB
03_handmade_02.txt
AC
106 ms
66860 KiB
03_handmade_03.txt
AC
113 ms
66836 KiB
03_handmade_04.txt
AC
102 ms
51536 KiB
03_handmade_05.txt
AC
99 ms
51472 KiB
03_handmade_06.txt
AC
98 ms
51428 KiB