結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー FF256grhyFF256grhy
提出日時 2016-11-19 07:22:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 214 ms / 5,000 ms
コード長 2,661 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 78,912 KB
実行使用メモリ 17,892 KB
最終ジャッジ日時 2023-10-23 15:54:12
合計ジャッジ時間 8,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 165 ms
12,724 KB
testcase_13 AC 176 ms
13,176 KB
testcase_14 AC 206 ms
10,784 KB
testcase_15 AC 159 ms
14,448 KB
testcase_16 AC 193 ms
11,984 KB
testcase_17 AC 193 ms
12,076 KB
testcase_18 AC 165 ms
12,668 KB
testcase_19 AC 202 ms
10,844 KB
testcase_20 AC 200 ms
10,684 KB
testcase_21 AC 173 ms
13,076 KB
testcase_22 AC 176 ms
13,204 KB
testcase_23 AC 165 ms
12,888 KB
testcase_24 AC 189 ms
11,968 KB
testcase_25 AC 183 ms
10,124 KB
testcase_26 AC 200 ms
7,300 KB
testcase_27 AC 174 ms
12,964 KB
testcase_28 AC 175 ms
13,156 KB
testcase_29 AC 200 ms
10,744 KB
testcase_30 AC 161 ms
14,332 KB
testcase_31 AC 178 ms
13,356 KB
testcase_32 AC 199 ms
10,384 KB
testcase_33 AC 189 ms
11,396 KB
testcase_34 AC 189 ms
10,452 KB
testcase_35 AC 164 ms
14,036 KB
testcase_36 AC 186 ms
10,460 KB
testcase_37 AC 179 ms
17,892 KB
testcase_38 AC 214 ms
10,868 KB
testcase_39 AC 190 ms
10,868 KB
testcase_40 AC 192 ms
10,868 KB
testcase_41 AC 146 ms
12,044 KB
testcase_42 AC 145 ms
12,048 KB
testcase_43 AC 173 ms
8,796 KB
testcase_44 AC 122 ms
11,704 KB
testcase_45 AC 134 ms
17,892 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:63:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   63 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:64:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |         inc(i, n) { scanf("%d", &l[i]); }
      |                     ~~~~~^~~~~~~~~~~~~
main.cpp:65:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |         scanf("%d", &t);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cmath>

#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

typedef long long   signed int LL;
typedef long long unsigned int LU;

template<typename T> void swap(T &x, T &y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, l[26], t;
int ac[26], counter, score[100000], at[100000];
std::map<std::string, int> m;

struct Node { int right_num, left, right; };
class Tree {
	Node node[31 * 100000];
	int ptr = 1;
public:
	void insert(int v) { search(v,  1); }
	void  erase(int v) { search(v, -1); }
	int find(int v) { return search(v, 0); }
	int search(int v, int diff);
};
int Tree::search(int v, int diff) {
	int r[32], rank = 0;
	r[0] = 0;
	inc(i, 31) {
		bool is_left = ((v & (1 << (30 - i))) == 0);
		if(is_left) { rank += node[ r[i] ].right_num; } else { node[ r[i] ].right_num += diff; }
		int & rr = (is_left ? node[ r[i] ].left : node[ r[i] ].right);
		if(rr == 0) { rr = ptr++; }
		r[i + 1] = rr;
	}
	return rank;
}

Tree v;

int main() {
	scanf("%d", &n);
	inc(i, n) { scanf("%d", &l[i]); }
	scanf("%d", &t);
	inc(i, t) {
		std::string name;
		char p;
		std::cin >> name >> p;
		if(p != '?') {
			auto it = m.find(name);
			bool new_flag = (it == m.end());
			if(new_flag) {
				it = (m.insert(std::make_pair(name, counter++))).first;
			}
			int id = it -> second;
			int prob = p - 'A';
			ac[prob]++;
			int plus = ( 50 * l[prob] + (500 * l[prob]) / (8 + 2 * ac[prob]) ) * 100001 + at[id] - i;
			at[id] = i;
			if(new_flag) {
				v.insert(plus);
			} else {
				v.erase(score[id]);
				v.insert(score[id] + plus);
			}
			score[id] += plus;
		} else {
			int id = m.find(name) -> second;
			printf("%d\n", v.find(score[id]) + 1);
		}
	}
	
	return 0;
}
0