이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(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)
template <class X, class Y>
inline bool maximize(X &x, Y y) {
return (x < y ? x = y, true : false);
}
template <class X, class Y>
inline bool minimize(X &x, Y y) {
return (x > y ? x = y, true : false);
}
template <class X>
inline void compress(vector<X> &a) {
sort(all(a));
a.resize(unique(all(a)) - a.begin());
}
int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
return l + abs((ll) rng()) % (r - l + 1);
}
const ll oo = (ll) 1e17;
const int inf = (ll) 2e9 + 7, mod = (ll) 998244353;
const int mxn = 2e5 + 5, BLOCK = (int) 700;
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
int n, t;
#define operator(type) bool operator type (const Pair &p) const
struct Pair {
int l, r;
operator(<) { return r - l < p.r - p.l; }
// operator(==) { return mp(l, r) == mp(p.l, p.r); }
};
struct {
vector<Pair> out, in;
vector<int> ls[mxn / BLOCK + 5], rs[mxn / BLOCK + 5];
void ins(Pair p) {
in.pb(p);
if (sz(in) < BLOCK) return;
for (Pair p : in) out.pb(p);
in.clear();
sort(all(out));
int m = sz(out);
forn(i, 0, (m - 1) / BLOCK) {
ls[i].clear(); rs[i].clear();
}
forn(i, 0, m - 1) {
ls[i / BLOCK].pb(out[i].l);
rs[i / BLOCK].pb(out[i].r);
}
forn(i, 0, (m - 1) / BLOCK) {
sort(all(ls[i])); sort(all(rs[i]));
}
}
int calc(int l, int r, int k) {
if (r - l + 1 < k) return 0;
int ans = 0;
for (Pair &p : in) {
if (min(r, p.r) - max(l, p.l) + 1 >= k)
ans++;
}
forn(i, 0, (sz(out) - 1) / BLOCK) {
int u = i * BLOCK;
int v = min((i + 1) * BLOCK - 1, sz(out) - 1);
if (u > v) continue;
if (out[u].r - out[u].l + 1 >= k) {
ans += (v - u + 1);
ans -= ls[i].end() - upper_bound(all(ls[i]), r - k + 1);
ans -= lower_bound(all(rs[i]), l + k - 1) - rs[i].begin();
}
else if (out[v].r - out[v].l + 1 >= k) {
forn(t, u, v) {
if (min(r, out[t].r) - max(l, out[t].l) + 1 >= k)
ans++;
}
}
}
return ans;
}
} cur, rev;
Pair p[mxn];
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define TASK "input"
if (fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
}
cin >> n >> t;
int timer = 0;
int type, a, b, id, x;
int ans = 0;
rep(_, n) {
cin >> type;
if (type == 1) {
cin >> a >> b;
a = a ^ (t * ans);
b = b ^ (t * ans);
if (a > b) swap(a, b);
cur.ins(p[++timer] = {a, b});
}
else if (type == 2) {
cin >> id;
rev.ins(p[id]);
}
else {
cin >> a >> b >> x;
a = a ^ (t * ans);
b = b ^ (t * ans);
if (a > b) swap(a, b);
ans = cur.calc(a, b, x) - rev.calc(a, b, x);
cout << ans << '\n';
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'int main()':
segments.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
129 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |