QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#461760 | #6881. The Mine of Abyss | mduba | AC ✓ | 662ms | 11084kb | C++20 | 9.8kb | 2024-07-03 01:14:01 | 2024-07-03 01:14:01 |
Judging History
answer
//#pragma comment(linker, "/stack:20000000")
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define se second
#define fi first
#define ld long double
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define ull unsigned long long
#define y1 y12313312312
#define vd vasvsadasdasfdasf
#define endl '\n'
#define gcd __gcd
#define b_p __builtin_popcountll
#define next nqweqweeqeqe
#define prev ppawfawfpfaw
#define pii pair < int, int >
#define pdd pair < double, double >
#define vi vector < int >
#define vpii vector < pii >
#define vpdd vector < pdd >
#define si set < int >
#define spii set < pii >
#define mii map < int, int >
#define umii unordered_map < int, int >
#define msi multiset < int >
#define qi queue < int >
#define qpii queue < pii >
#define mci map < char, int >
#define mdi map < double, int >
#define all(x) x.begin(), x.end()
#define mems(x, y) memset(x, y, sizeof x)
#define srt(x, y) sort(x + 1, x + y + 1)
#define rvs(x, y) reverse(x + 1, x + y + 1)
#define FOR(i, x, y) for (int i = x; i <= y; i++)
#define FOR1(i, x, y, z) for(int i = x; i <= y; i += z)
#define ROF(i, x, y) for (int i = x; i >= y; i--)
#define ROF1(i, x, y, z) for (int i = x; i >= y; i -= z)
#define uniq(x); sort(all(x)); x.resize(unique(all(x)) - x.begin());
#define mid ((tl + tr) >> 1)
#define LS v + v, tl, mid
#define RS v + v + 1, mid + 1, tr
#define int ll
using namespace std;
using namespace __gnu_pbds;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class U> bool emin(T& a, const U& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b)
template <class T, class U> bool emax(T& a, const U& b) { return a < b ? a = b, 1 : 0; } // set a = max(a,b)
template <class T, class U> void erase(T& t, const U& u) { // don't erase
auto it = t.find(u); //assert(it != end(t));
if (it != t.end()) t.erase(it);
}
inline namespace FileIO {
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
//cin.tie(0)->sync_with_stdio(0); // unsync C / C++ I/O streams
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// cin.exceptions(cin.failbit);
// throws exception when do smth illegal
// ex. try to read letter into int
if (s.ss) setIn(s+".in"), setOut(s+".out"); // for old USACO
}
}
int MOD = 1e9 + 33;
#ifndef int
struct Mint
{
private:
int normal(int x) { if (x >= MOD) x -= MOD; if (x < 0) x += MOD; return x;}
int power(int x, int y) { int res = 1; for (;y;y >>= 1, x = (x * x) % MOD) if (y & 1) res = (res * x) % MOD; return res;}
public:
int x;
Mint():x(0){}
Mint(int y):x(normal(y)){}
Mint operator -()const {return Mint(MOD - x);}
Mint operator +(const Mint y) {return Mint(x + y.x);}
Mint operator -(const Mint y) {return Mint(x - y.x);}
Mint operator *(const Mint y) {return Mint(int((ll)x * y.x % MOD));}
Mint operator *(const int y) {return Mint(int((ll)x * y % MOD));}
Mint operator /(const Mint y) {return Mint(int((ll)x * power(y.x, MOD - 2) % MOD));}
Mint &operator =(const Mint y) {x = normal(y.x); return *this;}
Mint &operator +=(const Mint y) {x = normal(x + y.x); return *this;}
Mint &operator -=(const Mint y) {x = normal(x - y.x); return *this;}
Mint &operator *=(const Mint y) {x = int((ll)x * y.x % MOD); return *this;}
Mint &operator *=(const int y) {x = int((ll)x * y % MOD); return *this;}
Mint &operator /=(const Mint y) {x = int((ll)x * power(y.x, MOD - 2) % MOD); return *this;}
bool operator ==(const int y) {return x == y;}
};
ostream& operator << (ostream& out, const Mint& x){ out << x.x; return out;}
#endif // int
template < typename T, typename TT > ostream& operator << (ostream& out, const pair < T, TT>& p) {out << p.fi << " " << p.se; return out;}
template < typename T, typename TT > pair < T, TT > operator + (const pair < T, TT >& p1, const pair < T, TT >& p2) {return make_pair(p1.fi + p2.fi, p1.se + p2.se);}
template < typename T, typename TT > pair < T, TT > operator += (pair < T, TT >& p1, const pair < T, TT>& p2) {p1.fi += p2.fi; p1.se += p2.se; return p1;}
int bp (int x, int y)
{
ll res = 1;
for (; y; y >>= 1, x = (x * x))
if (y & 1) res = (res * x);
return res;
}
ll bpm(ll x, ll y, ll md = MOD)
{
ll res = 1;
for (; y; y >>= 1, x = (x * x) % md)
if (y & 1) res = (res * x) % md;
return res;
}
/*
inline void normal(ll &x, int md = MOD)
{
if (x < md && x >= 0) return;
x %= md;
if (x < 0) x += md;
}
inline int MUL(ll x, ll y, int md = MOD)
{
normal(x, md); normal(y, md);
return (x * y) % md;
}
inline int SQ(ll x, int md = MOD)
{
normal(x, md);
return MUL(x, x, md);
}
inline int ADD(int x, int y, int md = MOD)
{
normal(x, md); normal(y, md);
return (x + y >= md ? x + y - md : x + y);
}
inline int SUB(int x, int y, int md = MOD)
{
normal(x, md); normal(y, md);
x -= y;
if (x < 0) x += md;
return x;
}
inline int DIV(ll x, ll y, int md = MOD)
{
normal(x, md); normal(y, md);
y = bpm(y, md - 2, md);
return MUL(x, y, md);
}*/
bool is_prime(int x)
{
if (x <= 1) return 0;
for (int i = 2; i * i <= x; i++) if (x % i == 0) return 0;
return 1;
}
inline int cd(char c){return c - '0';}
inline char cc(int x){return x + '0';}
inline char cb(int x){return x + 'A';}
inline int cn(char c){return c - 'A';}
inline int diff(int x, int y){return abs(x - y);}
inline void abandon(){cout << "NO";exit(0);}
inline int rng(int l, int r){return (rnd() % (r - l + 1) + l);}
inline int pw2(int i){return (1 << i);}
inline bool bit(int mask, int i){return ((mask >> i) & 1);}
inline int lcm(int x, int y) {return (x / gcd(x, y)) * y;}
inline int sign(int x) {return (x < 0 ? -1 : !!x);}
inline void coutmask(int mask, int sz) {FOR (i, 0, sz - 1) cout << bit(mask, i);}
const ll INF = 1e15 + 7;
const int N = 1e5 + 40, T = 4 * N, logN = (int)log2(N) + 2, Nlog = N * logN * 2, basic = 41/*379999*/, inf = 1e9 + 7, Mod = 998244353, /*NWSE or ULDR*/sx[4] = {-1, 0, 1, 0}, sy[4] = {0, -1, 0, 1}, mod = 1e9 + 3;
const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dy[8] = {1, 0, -1, 1, -1, 1, 0, -1}, sqN = (int)sqrt(N), BL = 316, BL2 = 1000;
const double eps = 1e-12, pi = acos(-1);
int n, m, r, l, e, id, mx = -inf, mn = inf, w, timer, tst, delta = 2e8 + 1;
int a[N], b[N];
vpii t[T];
int f;
pii inter(pii p1, pii p2)
{
if (p1.fi > p2.fi) swap(p1, p2);
if (p1.se > p2.se) return p1;
if (p1.se >= p2.fi - 1) return {p1.fi, p2.se};
return {-1, -1};
}
vpii mer(vpii v1, vpii v2)
{
vpii v;
for (auto i : v1)
{
for (auto j : v2)
{
v.pb({i.fi + j.fi, i.se + j.se});
}
}
for (auto i : v1) v.pb(i);
for (auto i : v2) v.pb(i);
sort(all(v));
/*
cout << "MERGING ";
for (auto i : v) cout << i << ", ";
cout << endl;*/
vpii ans;
l = 0;
for (auto i : v)
{
if (!l)
{
l = i.fi;
r = i.se;
}
else
{
if (i.fi > r + 1)
{
ans.pb({l, r});
l = i.fi;
r = i.se;
}
else emax(r, i.se);
}
}
ans.pb({l, r});/*
cout << "INTO ";
for (auto i : ans) cout << i << ", ";
cout << endl;*/
return ans;
}
void build(int v, int tl, int tr)
{
if (tl == tr)
{
t[v].clear();
t[v].pb({a[tl], b[tl]});
return;
}
int mi = (tl + tr) / 2;
build(v + v, tl, mi);
build(v + v + 1, mi + 1, tr);
//cout << "MERGING " << tl << " " << mi << " with " << mi + 1 << " " << tr << endl;
t[v] = mer(t[v + v], t[v + v + 1]);
}
void upd(int v, int tl, int tr, int pos, pii val)
{
if (tl == tr)
{
t[v].clear();
t[v].pb(val);
return;
}
int mi = (tl + tr) / 2;
if (pos <= mi) upd(v + v, tl, mi, pos, val);
else upd(v + v + 1, mi + 1, tr, pos, val);
t[v] = mer(t[v + v], t[v + v + 1]);
}
vpii get(int v, int tl, int tr, int l, int r)
{
if (tl >= l && tr <= r)
{
return t[v];
}
if (tl > r || tr < l)
{
vpii cur;
return cur;
}
int mi = (tl + tr) / 2;
return mer(get(v + v, tl, mi, l, r), get(v + v + 1, mi + 1, tr, l, r));
}
void solve()
{
ll x = 0, y = 0, z = 0;
cin >> n >> m;
FOR (i, 1, n)
{
cin >> a[i] >> b[i];
}
build(1, 1, n);
FOR (i, 1, m)
{
int type;
cin >> type;
if (type == 1)
{
cin >> x >> l >> r;
upd(1, 1, n, x, {l, r});
}
else
{
cin >> l >> r;
auto v = get(1, 1, n, l, r);
f = 0;
for (auto i : v)
{
//cout << i << endl;
f += i.se - i.fi + 1;
}
cout << f + 1 << endl;
}
}
}
signed main()
{
int x, y, z;
//setprecision(9);
#ifdef LOCAL
setIn("input.txt");
setOut("output.txt");
#else
setIO();
#endif
int _ = 1;
cin >> _;
for (int i = 1; i <= _; ++i)
{
//cout << "Case " << i << ": ";
solve();
//cout << "\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 662ms
memory: 11084kb
input:
5 50000 50000 66335693 455373104 899598534 953840292 368422768 959249831 322335641 856660797 480850713 530968323 444246089 548960441 177553896 210027481 240619910 965196933 107673862 824855024 92241752 129406040 4394331 263058383 165733990 352925680 548298523 585259106 87906940 102933202 56167973 68...
output:
6347314288230 13412326698823 14303672645309 10014078679793 3207056352395 17712636872598 6895088186582 2708865372007 13359299717471 7521970208616 29403542534309 19086646921794 22131828538506 3925621911951 8121263956040 2791149376358 11044093486507 7978219310275 3019861426855 7716880379924 66583487561...
result:
ok 125000 lines