이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define lft(x) x * 2
#define rgt(x) x * 2 + 1
#define tm hui_pizda
#define ft first
#define sd second
#define pb push_back
#define pf push_front
#define sz size()
#define cnt continue
#define m_p make_pair
#define fr(i, l, r) for(int i = l; i <= r; ++ i)
#define rf(i, r, l) for(int i = r; i >= l; -- i)
#define all(x) x.begin(), x.end()
//#pragma GCC optimize(-O3)
//#pragma GCC optimize(Ofast)
//#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using _set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <pii> vpi;
typedef vector <pll> vpl;
mt19937_64 rnd(time(NULL));
const ll N = 1e6;
const ll mtrxN = 10;
const ll oo = 1e18 + 10;
const ll B = 500;
const ll mod = 1e9 + 7;
const ll B1 = 1500;
const ll B2 = 1500;
struct mtrx{
ll m[mtrxN][mtrxN] = {};
};
mtrx mtrx_mult(mtrx a, mtrx b){
mtrx c;
fr(i, 0, mtrxN - 1){
fr(j, 0, mtrxN - 1){
ll sum = 0;
fr(x, 0, mtrxN - 1){
sum += a.m[i][x] * b.m[x][j];
sum %= mod;
}
c.m[i][j] = sum;
}
}
return c;
}
mtrx mtrx_pow(mtrx a, ll n){
mtrx res;
fr(i, 0, mtrxN - 1)fr(j, 0, mtrxN - 1)res.m[i][j] = a.m[i][j];
n --;
while(n){
if(n&1)res = mtrx_mult(res, a);
a = mtrx_mult(a, a);
n >>= 1;
}
return res;
}
ll _pow(ll a, ll n){
ll r = 1;
while(n){
if(n&1)r = r * a % mod;
a = a * a % mod;
n >>= 1;
}
return r;
}
ll div(ll x, ll y, ll md){
return x * _pow(y, md - 2) % md;
}
ll lastans, last = 1, n, t, i, a, b, k, l, r, now, usd[N], mn[N], mx[N];
vpl temp, sqd1, sqd2, deleted, aded;
vl sqd3, sqd4;
pll o[N];
ll cnv(ll a){
return (t * lastans) ^ a;
}
ll get1(ll l, ll r, ll x){
ll last = 0, ans = 0;
for(ll i = B2; i < (ll)sqd1.sz; i += B2){
if(mx[i] < l || mn[i] > r);
else if(mn[i] < l && l <= mx[i] || mn[i] <= r && r < mx[i]){
//посчитать вручную
//cout << "last: " << last << " i: " << i << endl;
fr(j, last, i - 1)
if(sqd1[j].sd >= l && sqd1[j].sd <= r && sqd1[j].ft >= x)ans ++;
} else{
ll pos = lower_bound(sqd3.begin() + last, sqd3.begin() + i, x) - sqd3.begin();
ans += i - pos;
}
last = i;
}
fr(i, last, (ll)sqd1.sz - 1)
if(sqd1[i].sd >= l && sqd1[i].sd <= r && sqd1[i].ft >= x)ans ++;
return ans;
}
ll get2(ll l, ll r, ll x){
ll last = 0, ans = 0;
for(ll i = B2; i < (ll)sqd2.sz; i += B2){
if(mx[i] < l || mn[i] > r);
else if(mn[i] < l && l <= mx[i] || mn[i] <= r && r < mx[i]){
//посчитать вручную
fr(j, last, i - 1)
if(sqd2[j].sd >= l && sqd2[j].sd <= r && sqd2[j].ft >= x)ans ++;
} else{
ll pos = lower_bound(sqd4.begin() + last, sqd4.begin() + i, x) - sqd4.begin();
ans += i - pos;
}
last = i;
}
fr(i, last, (ll)sqd2.sz - 1)
if(sqd2[i].sd >= l && sqd2[i].sd <= r && sqd2[i].ft >= x)ans ++;
return ans;
}
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> t;
fr(tr, 1, n){
cin >> i;
if(i == 1){
cin >> a >> b;
l = cnv(a);
r = cnv(b);
if(l > r)swap(l, r);
o[++ now] = {l, r};
aded.pb({l, r});
}
if(i == 2){
ll d;
cin >> d;
//удалить отрезок l..r
usd[d] = 1;
deleted.pb({o[d].ft, o[d].sd});
}
if(i == 3){
cin >> a >> b >> k;
l = cnv(a);
r = cnv(b);
if(l > r)swap(l, r);
//(кол-во чисел с li 1..l - 1 и ri >= l + k - 1) + (кол-во чисел с li l..r - k + 1 и ri - li + 1)
//пройтись по накопленному вектору отрезков
lastans = 0;
for(auto i : aded)
if(i.ft < l && i.sd >= l + k - 1 || i.ft >= l && i.ft <= r - k + 1 && i.sd - i.ft + 1 >= k)lastans ++;
for(auto i : deleted)
if(i.ft < l && i.sd >= l + k - 1 || i.ft >= l && i.ft <= r - k + 1 && i.sd - i.ft + 1 >= k)lastans --;
//взять ответ из посчитанной ранее sqrtdecompompozition
lastans += get1(1, l - 1, l + k - 1);
lastans += get2(l, r - k + 1, k);
// cout << " ";
cout << lastans << "\n";
}
if(tr % B1 == 0){
temp.clear();
fr(i, 1, now){
if(usd[i])cnt;
temp.pb(o[i]);
}
sort(temp.begin(), temp.end());
vpl temp2, temp3;
aded.clear();
deleted.clear();
sqd1.clear();
sqd2.clear();
sqd3.clear();
sqd4.clear();
ll n = oo, x = -oo;
fr(i, 0, (ll)temp.sz - 1){
if(i != 0 && i % B2 == 0){
mn[i] = n, mx[i] = x;
sort(temp2.begin(), temp2.end());
sort(temp3.begin(), temp3.end());
for(auto i : temp2)sqd1.pb(i), sqd3.pb(i.ft);
for(auto i : temp3)sqd2.pb(i), sqd4.pb(i.ft);
n = oo, x = -oo;
temp2.clear();
temp3.clear();
}
temp2.pb({temp[i].sd, temp[i].ft});
temp3.pb({temp[i].sd - temp[i].ft + 1, temp[i].ft});
n = min(n, temp[i].ft);
x = max(x, temp[i].ft);
}
sort(temp2.begin(), temp2.end());
sort(temp3.begin(), temp3.end());
for(auto i : temp2)sqd1.pb(i), sqd3.pb(i.ft);
for(auto i : temp3)sqd2.pb(i), sqd4.pb(i.ft);
last = now + 1;
}
}
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp:42:20: warning: overflow in implicit constant conversion [-Woverflow]
const ll oo = 1e18 + 10;
~~~~~^~~~
segments.cpp: In function 'll get1(ll, ll, ll)':
segments.cpp:103:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
else if(mn[i] < l && l <= mx[i] || mn[i] <= r && r < mx[i]){
~~~~~~~~~~^~~~~~~~~~~~~
segments.cpp: In function 'll get2(ll, ll, ll)':
segments.cpp:123:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
else if(mn[i] < l && l <= mx[i] || mn[i] <= r && r < mx[i]){
~~~~~~~~~~^~~~~~~~~~~~~
segments.cpp: In function 'int main()':
segments.cpp:171:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(i.ft < l && i.sd >= l + k - 1 || i.ft >= l && i.ft <= r - k + 1 && i.sd - i.ft + 1 >= k)lastans ++;
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
segments.cpp:173:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(i.ft < l && i.sd >= l + k - 1 || i.ft >= l && i.ft <= r - k + 1 && i.sd - i.ft + 1 >= k)lastans --;
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# | 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... |