結果

問題 No.469 区間加算と一致検索の問題
ユーザー bal4ubal4u
提出日時 2019-08-11 20:50:15
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 191 ms / 5,000 ms
コード長 1,744 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 30,016 KB
実行使用メモリ 150,380 KB
最終ジャッジ日時 2023-10-12 01:04:57
合計ジャッジ時間 9,076 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 17 ms
17,260 KB
testcase_04 AC 21 ms
20,312 KB
testcase_05 AC 25 ms
23,168 KB
testcase_06 AC 28 ms
26,624 KB
testcase_07 AC 29 ms
27,816 KB
testcase_08 AC 32 ms
30,692 KB
testcase_09 AC 14 ms
13,796 KB
testcase_10 AC 7 ms
6,856 KB
testcase_11 AC 10 ms
9,928 KB
testcase_12 AC 34 ms
32,420 KB
testcase_13 AC 22 ms
20,532 KB
testcase_14 AC 8 ms
7,360 KB
testcase_15 AC 12 ms
11,904 KB
testcase_16 AC 31 ms
29,112 KB
testcase_17 AC 27 ms
25,396 KB
testcase_18 AC 28 ms
26,876 KB
testcase_19 AC 6 ms
6,188 KB
testcase_20 AC 34 ms
31,536 KB
testcase_21 AC 9 ms
8,532 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 123 ms
108,408 KB
testcase_24 AC 120 ms
108,352 KB
testcase_25 AC 121 ms
108,368 KB
testcase_26 AC 121 ms
108,160 KB
testcase_27 AC 122 ms
108,804 KB
testcase_28 AC 125 ms
108,640 KB
testcase_29 AC 120 ms
108,388 KB
testcase_30 AC 121 ms
108,364 KB
testcase_31 AC 121 ms
108,264 KB
testcase_32 AC 121 ms
108,592 KB
testcase_33 AC 191 ms
150,204 KB
testcase_34 AC 189 ms
150,172 KB
testcase_35 AC 189 ms
149,940 KB
testcase_36 AC 188 ms
150,380 KB
testcase_37 AC 187 ms
150,012 KB
testcase_38 AC 174 ms
137,652 KB
testcase_39 AC 171 ms
137,932 KB
testcase_40 AC 173 ms
137,928 KB
testcase_41 AC 174 ms
138,288 KB
testcase_42 AC 173 ms
137,920 KB
testcase_43 AC 172 ms
137,188 KB
testcase_44 AC 178 ms
138,264 KB
testcase_45 AC 173 ms
137,496 KB
testcase_46 AC 173 ms
137,596 KB
testcase_47 AC 171 ms
137,668 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 175 ms
137,964 KB
testcase_51 AC 171 ms
137,512 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:10:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:18:24: 備考: in expansion of macro ‘gc’
   18 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:11:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   11 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:31:17: 備考: in expansion of macro ‘pc’
   31 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: No.469 区間加算と一致検索の問題
// bal4u 2019.8.11

#include <stdio.h>

typedef unsigned long long ll;

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 非負整数の表示(出力)
	int i;
	char b[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

//// ハッシュ関数
#define HASHSIZ 9999991
typedef struct { ll s; int id; } HASH;
HASH hash[HASHSIZ+5], *hashend = hash + HASHSIZ;

int lookup(ll s) {
	HASH *p = hash + (int)(s % HASHSIZ);
	while (p->s) {
		if (p->s == s) return p->id;
		if (++p == hashend) p = hash;
	}
	return -1;
}

void insert(ll s, int id) {
	HASH *p = hash + (int)(s % HASHSIZ);
	while (p->s) {
		if (p->s == s) return;
		if (++p == hashend) p = hash;
	}
	p->s = s, p->id = id;
}

//// 疑似乱数発生
unsigned xorshift() {
    static unsigned y = 2463534242;
	y = y ^ (y << 13), y = y ^ (y >> 17), y = y ^ (y << 5);
	return y;
}

ll phash[1000005];

int main()
{
	int i, N, Q, x; unsigned r;
	ll s;

	N = in(), Q = in();
	r = xorshift();
	phash[0] = 1; for (i = 1; i <= N; i++) phash[i] = phash[i - 1] * r;

	s = 0;
	insert(s+1, 0);
	for (i = 1; i <= Q; i++) {
		x = gc(), gc();
		if (x == '?') {
			x = lookup(s+1);
			out(x < 0? i: x);
		} else {
			int l = in(), r = in(), k = in();
			s += (ll)(phash[r] - phash[l]) * k;
			insert(s+1, i);
		}
	}
	return 0;
}
0