Submission #422889

# Submission time Handle Problem Language Result Execution time Memory
422889 2021-06-10T13:43:33 Z abdzag Crossing (JOI21_crossing) C++17
3 / 100
760 ms 34720 KB
#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;
	rep(i, 1, n) {
		hashed[i] = hashed[i - 1] * C;
	}
	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

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 time Memory Grader output
1 Correct 396 ms 840 KB Output is correct
2 Correct 399 ms 836 KB Output is correct
3 Correct 438 ms 880 KB Output is correct
4 Correct 397 ms 852 KB Output is correct
5 Correct 383 ms 836 KB Output is correct
6 Correct 369 ms 864 KB Output is correct
7 Correct 385 ms 816 KB Output is correct
8 Correct 394 ms 816 KB Output is correct
9 Correct 384 ms 844 KB Output is correct
10 Correct 425 ms 800 KB Output is correct
11 Correct 388 ms 1000 KB Output is correct
12 Correct 388 ms 872 KB Output is correct
13 Correct 384 ms 856 KB Output is correct
14 Correct 385 ms 964 KB Output is correct
15 Correct 394 ms 836 KB Output is correct
16 Correct 385 ms 976 KB Output is correct
17 Correct 388 ms 836 KB Output is correct
18 Correct 428 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 396 ms 840 KB Output is correct
2 Correct 399 ms 836 KB Output is correct
3 Correct 438 ms 880 KB Output is correct
4 Correct 397 ms 852 KB Output is correct
5 Correct 383 ms 836 KB Output is correct
6 Correct 369 ms 864 KB Output is correct
7 Correct 385 ms 816 KB Output is correct
8 Correct 394 ms 816 KB Output is correct
9 Correct 384 ms 844 KB Output is correct
10 Correct 425 ms 800 KB Output is correct
11 Correct 388 ms 1000 KB Output is correct
12 Correct 388 ms 872 KB Output is correct
13 Correct 384 ms 856 KB Output is correct
14 Correct 385 ms 964 KB Output is correct
15 Correct 394 ms 836 KB Output is correct
16 Correct 385 ms 976 KB Output is correct
17 Correct 388 ms 836 KB Output is correct
18 Correct 428 ms 968 KB Output is correct
19 Correct 760 ms 34560 KB Output is correct
20 Correct 691 ms 34452 KB Output is correct
21 Correct 610 ms 32556 KB Output is correct
22 Correct 651 ms 29264 KB Output is correct
23 Correct 448 ms 2600 KB Output is correct
24 Correct 503 ms 2500 KB Output is correct
25 Correct 643 ms 34596 KB Output is correct
26 Correct 669 ms 34608 KB Output is correct
27 Correct 696 ms 34536 KB Output is correct
28 Correct 706 ms 34528 KB Output is correct
29 Correct 721 ms 33672 KB Output is correct
30 Correct 456 ms 2620 KB Output is correct
31 Correct 677 ms 34556 KB Output is correct
32 Correct 667 ms 31552 KB Output is correct
33 Correct 453 ms 2580 KB Output is correct
34 Correct 754 ms 34720 KB Output is correct
35 Correct 588 ms 25964 KB Output is correct
36 Correct 454 ms 2488 KB Output is correct
37 Correct 446 ms 2636 KB Output is correct
38 Correct 677 ms 34672 KB Output is correct
39 Correct 505 ms 34528 KB Output is correct
40 Incorrect 610 ms 23000 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 396 ms 840 KB Output is correct
2 Correct 399 ms 836 KB Output is correct
3 Correct 438 ms 880 KB Output is correct
4 Correct 397 ms 852 KB Output is correct
5 Correct 383 ms 836 KB Output is correct
6 Correct 369 ms 864 KB Output is correct
7 Correct 385 ms 816 KB Output is correct
8 Correct 394 ms 816 KB Output is correct
9 Correct 384 ms 844 KB Output is correct
10 Correct 425 ms 800 KB Output is correct
11 Correct 388 ms 1000 KB Output is correct
12 Correct 388 ms 872 KB Output is correct
13 Correct 384 ms 856 KB Output is correct
14 Correct 385 ms 964 KB Output is correct
15 Correct 394 ms 836 KB Output is correct
16 Correct 385 ms 976 KB Output is correct
17 Correct 388 ms 836 KB Output is correct
18 Correct 428 ms 968 KB Output is correct
19 Correct 390 ms 856 KB Output is correct
20 Correct 398 ms 860 KB Output is correct
21 Incorrect 391 ms 836 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 396 ms 840 KB Output is correct
2 Correct 399 ms 836 KB Output is correct
3 Correct 438 ms 880 KB Output is correct
4 Correct 397 ms 852 KB Output is correct
5 Correct 383 ms 836 KB Output is correct
6 Correct 369 ms 864 KB Output is correct
7 Correct 385 ms 816 KB Output is correct
8 Correct 394 ms 816 KB Output is correct
9 Correct 384 ms 844 KB Output is correct
10 Correct 425 ms 800 KB Output is correct
11 Correct 388 ms 1000 KB Output is correct
12 Correct 388 ms 872 KB Output is correct
13 Correct 384 ms 856 KB Output is correct
14 Correct 385 ms 964 KB Output is correct
15 Correct 394 ms 836 KB Output is correct
16 Correct 385 ms 976 KB Output is correct
17 Correct 388 ms 836 KB Output is correct
18 Correct 428 ms 968 KB Output is correct
19 Correct 760 ms 34560 KB Output is correct
20 Correct 691 ms 34452 KB Output is correct
21 Correct 610 ms 32556 KB Output is correct
22 Correct 651 ms 29264 KB Output is correct
23 Correct 448 ms 2600 KB Output is correct
24 Correct 503 ms 2500 KB Output is correct
25 Correct 643 ms 34596 KB Output is correct
26 Correct 669 ms 34608 KB Output is correct
27 Correct 696 ms 34536 KB Output is correct
28 Correct 706 ms 34528 KB Output is correct
29 Correct 721 ms 33672 KB Output is correct
30 Correct 456 ms 2620 KB Output is correct
31 Correct 677 ms 34556 KB Output is correct
32 Correct 667 ms 31552 KB Output is correct
33 Correct 453 ms 2580 KB Output is correct
34 Correct 754 ms 34720 KB Output is correct
35 Correct 588 ms 25964 KB Output is correct
36 Correct 454 ms 2488 KB Output is correct
37 Correct 446 ms 2636 KB Output is correct
38 Correct 677 ms 34672 KB Output is correct
39 Correct 505 ms 34528 KB Output is correct
40 Incorrect 610 ms 23000 KB Output isn't correct
41 Halted 0 ms 0 KB -