Submission #640457

#TimeUsernameProblemLanguageResultExecution timeMemory
640457FilyaSegments (IZhO18_segments)C++14
100 / 100
2428 ms15088 KiB
/////////////////////include///////////////////// //#include <bits/stdc++.h> #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <algorithm> #include <cmath> #include <cstring> #include <cassert> #include <set> #include <map> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <iomanip> #include <bitset> #include <stdio.h> #include <climits> #include <numeric> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; /////////////////////define///////////////////// #define ci(x) if(x) cout << "YES" << endl; else cout << "NO" << endl; #define cii(x) if(check(x)) #define MOD 1000000007 #define MOD2 998244353 #define oo 1e9 #define ool 1e18L #define pii pair<int, int> #define pll pair<long long, long long> #define mii map<int, int> #define vi vector<int> #define vpi vector<pair<int, int>> #define vll vector <ll> #define ff first #define ss second #define mp make_pair #define ll long long #define ld long double #define pb push_back #define eb emplace_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define bs binary_search #define sz(x) (int((x).size())) #define all(x) (x).begin(), (x).end() #define alll(x) (x), (x) + n #define clr(x) (x).clear(); #define fri(x) for(int i = 0; i < x; ++i) #define frj(x) for(int j = 0; j < x; ++j) #define frr(a, b) for(int i = a; i < b; ++i) #define frrj(a, b) for(int j = a; j < b; ++j) #define fra(x) for(int i = 0; i < x; ++i) cin >> a[i]; #define frb(x) for(int i = 0; i < x; ++i) cin >> b[i]; #define frs(x) for(auto it = x.begin(); it != x.end(); ++it) #define fr(x) for(auto it : x) //el #define fastio ios_base::sync_with_stdio(false); cin.tie(0); #define dbg(x) cerr << #x << ": " << x << endl; #define ce(x) cout << x << endl; #define uniq(x) x.resize(unique(all(x)) - x.begin()); //make all one after sorting #define blt __builtin_popcount /////////////////////print array, vector, deque, set, multiset, pair, map ///////////////////// void print(long long t) {cerr << t;} void print(int t) {cerr << t;} void print(string t) {cerr << t;} void print(char t) {cerr << t;} void print(double t) {cerr << t;} void print(long double t) {cerr << t;} void print(unsigned long long t) {cerr << t;} template <class T, class V> void print(T v[],V n) {cerr << "["; for(int i = 0; i < n; i++) {print(v[i]); cerr << " "; } cerr << "]"; cout << endl;} template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";} template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;} template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;} template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;} template <class T> void print(stack <T> v) {cerr << "[ "; stack<T> s = v; while(s.size()) {int i = s.top(); print(i); s.pop(); cerr << " ";} cerr << "]"; cout << endl;} template <class T> void print(queue <T> v) {cerr << "[ "; queue<T> s = v; while(s.size()) {int i = s.front(); print(i); s.pop(); cerr << " ";} cerr << "]"; cout << endl;} template <class T> void print(deque <T> v) {cerr << "[ "; deque<T> s = v; while(s.size()) {int i = s.front(); print(i); s.pop_front(); cerr << " ";} cerr << "]"; cout << endl;} template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;} template <class T, class V> void print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;} /////////////////////code///////////////////// vector<pll> segments[2], newseg[2]; ll k, maxk[2][600], blockcnt, blocksize; vll l_[2][600], r_[2][600]; pll a[200005]; bool good(pll& a, pll& b) { // print(a); print(b); bool f = (min(a.ss, b.ss) - max(a.ff, b.ff) + 1 >= k); dbg(f) return (min(a.ss, b.ss) - max(a.ff, b.ff) + 1 >= k); } bool cmp(pll &a, pll &b) { return (a.ss - a.ff < b.ss - b.ff); } void build(int id) { for(pll p : newseg[id]) segments[id].pb(p); newseg[id].clear(); fri(blockcnt) { l_[id][i].clear(); r_[id][i].clear(); maxk[id][i] = 0; } int n = segments[id].size(); sort(all(segments[id]), cmp); int x = 0, y = 0; fri(blockcnt) { y += blocksize; while(x < min(n, y)) { l_[id][i].pb(segments[id][x].ff); r_[id][i].pb(segments[id][x].ss); maxk[id][i] = max(maxk[id][i], segments[id][x].ss - segments[id][x].ff + 1); x++; } sort(all(l_[id][i])); sort(all(r_[id][i])); } } int getans(int l, int r, int id) { ll cnt1, cnt2, sz, ans = 0, block = 0, x; while(block < blockcnt && maxk[id][block] < k) block++; if(block < blockcnt) { x = block * blocksize; frr(x, blocksize + x) { //min(lastsize[id], pll p = {l, r}; // print(segments[id][i]); if(good(p, segments[id][i])) ans++; } block++; while(block < blockcnt) { sz = r_[id][block].size(); cnt1 = lb(all(r_[id][block]), k + l - 1) - r_[id][block].begin(); cnt2 = sz - (ub(all(l_[id][block]), r + 1 - k) - l_[id][block].begin()); ans += sz - cnt1 - cnt2; block++; } } return ans; } int main() { fastio; ll q, t, tp, l, r, lastans = 0, id = 1, ind; cin >> q >> t; blockcnt = sqrt(q / log(q)); blocksize = q / blockcnt; while(q--) { cin >> tp; if(tp == 1) { cin >> l >> r; if(t) { l = l ^ lastans; r = r ^ lastans; } if(l > r) swap(l, r); a[id] = {l, r}; id++; newseg[0].eb(l, r); if(newseg[0].size() >= blocksize) build(0); } else if(tp == 2) { cin >> ind; l = a[ind].ff; r = a[ind].ss; newseg[1].eb(l, r); if(newseg[1].size() >= blocksize) build(1); } else { cin >> l >> r >> k; if(t) { l = l ^ lastans; r = r ^ lastans; } if(l > r) swap(l, r); ll ans = 0; if(r - l + 1 >= k) { pll p1 = {l, r}; ans = getans(l, r, 0) - getans(l, r, 1); // dbg(getans(l, r, 0)) dbg(getans(l, r, 1)) dbg(ans) for(pll p : newseg[0]) if(good(p1, p)) ans++; for(pll p : newseg[1]) if(good(p1, p)) ans--; } cout << ans << '\n'; lastans = ans; } } return 0; } // ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ // ♥ ♥ ♥ ♥ ♥ ♥ ♥ // ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ // ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ // ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ // // God loves Fil, Fil accepts God's will

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:167:33: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  167 |             if(newseg[0].size() >= blocksize)
      |                ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
segments.cpp:174:33: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  174 |             if(newseg[1].size() >= blocksize)
      |                ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...