Submission #422898

#TimeUsernameProblemLanguageResultExecution timeMemory
422898abdzagCrossing (JOI21_crossing)C++17
26 / 100
824 ms34764 KiB
#include<bits/stdc++.h> #include<unordered_map> #define rep(i,a,b) for(int i=int(a);i<int(b);i++) #define rrep(i,a,b) for(int i=int(a);i>int(b);i--) #define trav(a,v) for(auto& a: v) #define sz(v) v.size() #define all(v) v.begin(),v.end() #define vi vector<int> typedef long long ll; typedef long double ld; typedef unsigned long long ull; //const long long inf = 1e15; using namespace std; /** * Author: Simon Lindholm * Date: 2016-10-08 * License: CC0 * Source: me * Description: Segment tree with ability to add or set values of large intervals, and compute max of intervals. * Can be changed to other things. * Use with a bump allocator for better performance, and SmallPtr or implicit indices to save memory. * Time: O(\log N). * Usage: Node* tr = new Node(v, 0, sz(v)); * Status: stress-tested a bit */ const int inf = 1e9; struct Node { Node* l = 0, * r = 0; ull lo, hi, mset = inf, madd = 1, val = 0, val0 = 0; Node(int lo, int hi) :lo(lo), hi(hi) {} // Large interval of -inf Node(vector<ull>& v, int lo, int hi) : lo(lo), hi(hi) { if (lo + 1 < hi) { int mid = lo + (hi - lo) / 2; l = new Node(v, lo, mid); r = new Node(v, mid, hi); val = l->val + r->val; val0 = l->val + r->val; } else val = val0 = v[lo]; } ull query(int L, int R) { if (R <= lo || hi <= L) return 0; if (L <= lo && hi <= R) return val; push(); return l->query(L, R) + r->query(L, R); } void set(int L, int R, int x) { if (R <= lo || hi <= L) return; if (L <= lo && hi <= R) mset = val = x, madd = 1; else { push(), l->set(L, R, x), r->set(L, R, x); val = l->val + r->val; } } void add(int L, int R, ull x) { if (R <= lo || hi <= L) return; if (L <= lo && hi <= R) { madd = 1; val = val0; if (mset != inf) mset += x; else madd *= x; val *= x; } else { push(), l->add(L, R, x), r->add(L, R, x); val = l->val + r->val; } } void push() { if (!l) { int mid = lo + (hi - lo) / 2; l = new Node(lo, mid); r = new Node(mid, hi); } if (mset != inf) l->set(lo, hi, mset), r->set(lo, hi, mset), mset = inf; else if (madd != 1) l->add(lo, hi, madd), r->add(lo, hi, madd), madd = 1; } }; int main() { cin.sync_with_stdio(false); ll n; cin >> n; string a, b, c; cin >> a >> b >> c; srand(n); vector<ull> primes = { 37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197 }; ull C = primes[rand()%primes.size()]; vector<ull> hashed(n); hashed[0] = 1; ll MOD = 1000000007; rep(i, 1, n) { hashed[i] = (hashed[i - 1] * C)%MOD; } ull val = 0; ll q; cin >> q; string t; cin >> t; rep(i, 0, n)val += hashed[i] * a[i]; Node* tree = new Node(hashed, 0, n); rep(i, 0, n)tree->add(i, i + 1, t[i]); cout << (tree->query(0, n) == val ? "Yes" : "No") << endl; rep(i, 0, q) { ll A, B; char d; cin >> A >> B >> d; tree->add(A - 1, B, d); //cout << val << endl; //cout << tree->query(0, n) << endl;; cout << (tree->query(0, n) == val ? "Yes" : "No") << endl; } return 0; }

Compilation message (stderr)

Main.cpp: In member function 'ull Node::query(int, int)':
Main.cpp:46:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   46 |   if (R <= lo || hi <= L) return 0;
      |       ~~^~~~~
Main.cpp:46:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   46 |   if (R <= lo || hi <= L) return 0;
      |                  ~~~^~~~
Main.cpp:47:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   47 |   if (L <= lo && hi <= R) return val;
      |       ~~^~~~~
Main.cpp:47:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   47 |   if (L <= lo && hi <= R) return val;
      |                  ~~~^~~~
Main.cpp: In member function 'void Node::set(int, int, int)':
Main.cpp:52:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   52 |   if (R <= lo || hi <= L) return;
      |       ~~^~~~~
Main.cpp:52:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   52 |   if (R <= lo || hi <= L) return;
      |                  ~~~^~~~
Main.cpp:53:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   53 |   if (L <= lo && hi <= R) mset = val = x, madd = 1;
      |       ~~^~~~~
Main.cpp:53:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   53 |   if (L <= lo && hi <= R) mset = val = x, madd = 1;
      |                  ~~~^~~~
Main.cpp: In member function 'void Node::add(int, int, ull)':
Main.cpp:61:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   61 |   if (R <= lo || hi <= L) return;
      |       ~~^~~~~
Main.cpp:61:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   61 |   if (R <= lo || hi <= L) return;
      |                  ~~~^~~~
Main.cpp:62:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   62 |   if (L <= lo && hi <= R) {
      |       ~~^~~~~
Main.cpp:62:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   62 |   if (L <= lo && hi <= R) {
      |                  ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...