답안 #422898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422898 2021-06-10T13:50:07 Z abdzag Crossing (JOI21_crossing) C++17
26 / 100
824 ms 34764 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;
	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

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) {
      |                  ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 358 ms 796 KB Output is correct
2 Correct 388 ms 844 KB Output is correct
3 Correct 403 ms 880 KB Output is correct
4 Correct 405 ms 896 KB Output is correct
5 Correct 385 ms 860 KB Output is correct
6 Correct 365 ms 928 KB Output is correct
7 Correct 376 ms 784 KB Output is correct
8 Correct 411 ms 836 KB Output is correct
9 Correct 381 ms 872 KB Output is correct
10 Correct 398 ms 1004 KB Output is correct
11 Correct 414 ms 1004 KB Output is correct
12 Correct 405 ms 968 KB Output is correct
13 Correct 429 ms 904 KB Output is correct
14 Correct 378 ms 808 KB Output is correct
15 Correct 408 ms 788 KB Output is correct
16 Correct 408 ms 868 KB Output is correct
17 Correct 394 ms 996 KB Output is correct
18 Correct 396 ms 900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 358 ms 796 KB Output is correct
2 Correct 388 ms 844 KB Output is correct
3 Correct 403 ms 880 KB Output is correct
4 Correct 405 ms 896 KB Output is correct
5 Correct 385 ms 860 KB Output is correct
6 Correct 365 ms 928 KB Output is correct
7 Correct 376 ms 784 KB Output is correct
8 Correct 411 ms 836 KB Output is correct
9 Correct 381 ms 872 KB Output is correct
10 Correct 398 ms 1004 KB Output is correct
11 Correct 414 ms 1004 KB Output is correct
12 Correct 405 ms 968 KB Output is correct
13 Correct 429 ms 904 KB Output is correct
14 Correct 378 ms 808 KB Output is correct
15 Correct 408 ms 788 KB Output is correct
16 Correct 408 ms 868 KB Output is correct
17 Correct 394 ms 996 KB Output is correct
18 Correct 396 ms 900 KB Output is correct
19 Correct 812 ms 34580 KB Output is correct
20 Correct 729 ms 34572 KB Output is correct
21 Correct 650 ms 32552 KB Output is correct
22 Correct 626 ms 29196 KB Output is correct
23 Correct 469 ms 2596 KB Output is correct
24 Correct 476 ms 2532 KB Output is correct
25 Correct 681 ms 34600 KB Output is correct
26 Correct 764 ms 34448 KB Output is correct
27 Correct 743 ms 34560 KB Output is correct
28 Correct 753 ms 34560 KB Output is correct
29 Correct 708 ms 33560 KB Output is correct
30 Correct 500 ms 2564 KB Output is correct
31 Correct 717 ms 34668 KB Output is correct
32 Correct 700 ms 31576 KB Output is correct
33 Correct 451 ms 2532 KB Output is correct
34 Correct 737 ms 34592 KB Output is correct
35 Correct 586 ms 26012 KB Output is correct
36 Correct 438 ms 2564 KB Output is correct
37 Correct 459 ms 2580 KB Output is correct
38 Correct 634 ms 34528 KB Output is correct
39 Correct 510 ms 34656 KB Output is correct
40 Correct 634 ms 23080 KB Output is correct
41 Correct 824 ms 34692 KB Output is correct
42 Correct 445 ms 34764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 358 ms 796 KB Output is correct
2 Correct 388 ms 844 KB Output is correct
3 Correct 403 ms 880 KB Output is correct
4 Correct 405 ms 896 KB Output is correct
5 Correct 385 ms 860 KB Output is correct
6 Correct 365 ms 928 KB Output is correct
7 Correct 376 ms 784 KB Output is correct
8 Correct 411 ms 836 KB Output is correct
9 Correct 381 ms 872 KB Output is correct
10 Correct 398 ms 1004 KB Output is correct
11 Correct 414 ms 1004 KB Output is correct
12 Correct 405 ms 968 KB Output is correct
13 Correct 429 ms 904 KB Output is correct
14 Correct 378 ms 808 KB Output is correct
15 Correct 408 ms 788 KB Output is correct
16 Correct 408 ms 868 KB Output is correct
17 Correct 394 ms 996 KB Output is correct
18 Correct 396 ms 900 KB Output is correct
19 Correct 385 ms 804 KB Output is correct
20 Correct 448 ms 976 KB Output is correct
21 Incorrect 400 ms 820 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 358 ms 796 KB Output is correct
2 Correct 388 ms 844 KB Output is correct
3 Correct 403 ms 880 KB Output is correct
4 Correct 405 ms 896 KB Output is correct
5 Correct 385 ms 860 KB Output is correct
6 Correct 365 ms 928 KB Output is correct
7 Correct 376 ms 784 KB Output is correct
8 Correct 411 ms 836 KB Output is correct
9 Correct 381 ms 872 KB Output is correct
10 Correct 398 ms 1004 KB Output is correct
11 Correct 414 ms 1004 KB Output is correct
12 Correct 405 ms 968 KB Output is correct
13 Correct 429 ms 904 KB Output is correct
14 Correct 378 ms 808 KB Output is correct
15 Correct 408 ms 788 KB Output is correct
16 Correct 408 ms 868 KB Output is correct
17 Correct 394 ms 996 KB Output is correct
18 Correct 396 ms 900 KB Output is correct
19 Correct 812 ms 34580 KB Output is correct
20 Correct 729 ms 34572 KB Output is correct
21 Correct 650 ms 32552 KB Output is correct
22 Correct 626 ms 29196 KB Output is correct
23 Correct 469 ms 2596 KB Output is correct
24 Correct 476 ms 2532 KB Output is correct
25 Correct 681 ms 34600 KB Output is correct
26 Correct 764 ms 34448 KB Output is correct
27 Correct 743 ms 34560 KB Output is correct
28 Correct 753 ms 34560 KB Output is correct
29 Correct 708 ms 33560 KB Output is correct
30 Correct 500 ms 2564 KB Output is correct
31 Correct 717 ms 34668 KB Output is correct
32 Correct 700 ms 31576 KB Output is correct
33 Correct 451 ms 2532 KB Output is correct
34 Correct 737 ms 34592 KB Output is correct
35 Correct 586 ms 26012 KB Output is correct
36 Correct 438 ms 2564 KB Output is correct
37 Correct 459 ms 2580 KB Output is correct
38 Correct 634 ms 34528 KB Output is correct
39 Correct 510 ms 34656 KB Output is correct
40 Correct 634 ms 23080 KB Output is correct
41 Correct 824 ms 34692 KB Output is correct
42 Correct 445 ms 34764 KB Output is correct
43 Correct 385 ms 804 KB Output is correct
44 Correct 448 ms 976 KB Output is correct
45 Incorrect 400 ms 820 KB Output isn't correct
46 Halted 0 ms 0 KB -