Submission #378562


Source Code Expand

#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>

using namespace std;

#define reE(i,a,b) for(auto (i)=(a);(i)<=(b);(i)++)
#define rE(i,b) reE(i,0,b)
#define reT(i,a,b) for(auto (i)=(a);(i)<(b);(i)++)
#define rT(i,b) reT(i,0,b)
#define rep(i,a,b) reE(i,a,b);
#define rev(i,a,b) for(auto (i)=(b)-1;(i)>=(a);(i)--)
#define fe(i,b) for (auto &(x):b);
#define itr(i,b) for(auto (i)=(b).begin();(i)!=(b).end();++(i))
#define rti(i,b) for(auto (i)=(b).rbegin();(i)!=(b).rend();++(i))
#define LL long long
#define all(b) (b).begin(),(b).end()

#define input_init stringstream ss; string strtoken, token; istringstream is
#define input_line  getline(cin, strtoken);is.str(strtoken);is.clear(istringstream::goodbit)
#define input_token(num) ss.str(""); ss.clear(stringstream::goodbit); getline(is, token, ','); ss << token; ss >> num

#define dir(xx,yy,x,y,i) (xx)=(x)+dir[(i)],(yy)=(y)+dir[(i)+1]

const LL INF = 1 << 30;

typedef pair<int,int> P;
#define st(x) (x).first
#define ed(x) (x).second
struct seg_Tree{
	P interval;
	LL child_max;
	LL add;
	int size(){return(ed(interval) - st(interval) + 1);}
	void set(int s, int t){
		st(interval) = s, ed(interval) = t;
	}
	seg_Tree(){
		add = 0, child_max = 0;
		set(1, 0);
	}

};

vector<string> istr;
vector<LL> inum;

set<string> uniq_num;
vector<string> work;
vector<seg_Tree> tree;
int n;
void make_tree(int k,int s, int t){
//	printf("%d[%d,%d]\n", k, s, t);
	if (s <= t){
		tree[k].set(s, t);
		if (tree[k].size() > 1){
			int l = 2 * k + 1;
			int r = l + 1;
			make_tree(l, s, (s + t) / 2);
			make_tree(r, (s + t) / 2+1,t);
		}
	}
}

void construct_tree(){
	int over_size = 1;
	while (over_size < (int)work.size())
		over_size <<= 1;
	tree.resize(over_size<<1, seg_Tree());
	make_tree(0, 0, (int)work.size() - 1);
}

LL add(int k, P len, LL val){
//	printf("%d[%d,%d](%lld)\n", k, st(len), ed(len),val);
	int l = 2 * k + 1;
	int r = l + 1;
	if (tree[k].interval == len)
		tree[k].add += val;
	else if (ed(len) <= ed(tree[l].interval))
		tree[k].child_max = max(tree[k].child_max, add(l, len, val));
	else if ((st(len) >= st(tree[r].interval)))
		tree[k].child_max = max(tree[k].child_max, add(r, len, val));
	else 
		tree[k].child_max = max(tree[k].child_max, max(add(l, make_pair(st(len), ed(tree[l].interval)), val), add(r, make_pair(st(tree[r].interval), ed(len)), val)));
	return(tree[k].add + tree[k].child_max);
}

int main(void){
	cin >> n;
	istr.resize(n); inum.resize(n);
	rT(i, n){
		cin >> istr[i] >> inum[i];
		reverse(all(istr[i]));
		uniq_num.insert(istr[i]);
	}
	work.reserve(uniq_num.size());
	for (auto &x : uniq_num)work.push_back(x);
	//rT(i, (int)work.size())printf("(%d,%s) ", i, work[i].c_str()); cout << endl;
	construct_tree();
	rT(i, n){
		int s, t;
		s = lower_bound(all(work), istr[i]) - work.begin();
		istr[i][istr[i].size()-1]++;
		t = lower_bound(all(work), istr[i]) - work.begin()-1;
		cout << add(0, P(s,t), inum[i])<<endl;
	}
	return(0);
}

Submission Info

Submission Time
Task E - 宝くじ
User btk15049
Language C++11 (GCC 4.9.2)
Score 200
Code Size 3286 Byte
Status AC
Exec Time 964 ms
Memory 24876 KB

Judge Result

Set Name All
Score / Max Score 200 / 200
Status
AC × 25
Set Name Test Cases
All scrambled_00.txt, scrambled_01.txt, scrambled_02.txt, scrambled_03.txt, scrambled_04.txt, scrambled_05.txt, scrambled_06.txt, scrambled_07.txt, scrambled_08.txt, scrambled_09.txt, scrambled_10.txt, scrambled_11.txt, scrambled_12.txt, scrambled_13.txt, scrambled_14.txt, scrambled_15.txt, scrambled_16.txt, scrambled_17.txt, scrambled_18.txt, scrambled_19.txt, scrambled_20.txt, scrambled_21.txt, scrambled_22.txt, scrambled_23.txt, scrambled_24.txt
Case Name Status Exec Time Memory
scrambled_00.txt AC 28 ms 800 KB
scrambled_01.txt AC 26 ms 920 KB
scrambled_02.txt AC 496 ms 8544 KB
scrambled_03.txt AC 460 ms 7580 KB
scrambled_04.txt AC 558 ms 8608 KB
scrambled_05.txt AC 329 ms 5532 KB
scrambled_06.txt AC 392 ms 6692 KB
scrambled_07.txt AC 135 ms 2596 KB
scrambled_08.txt AC 222 ms 4000 KB
scrambled_09.txt AC 502 ms 7196 KB
scrambled_10.txt AC 387 ms 6176 KB
scrambled_11.txt AC 144 ms 2464 KB
scrambled_12.txt AC 436 ms 6044 KB
scrambled_13.txt AC 106 ms 1952 KB
scrambled_14.txt AC 678 ms 15912 KB
scrambled_15.txt AC 47 ms 1308 KB
scrambled_16.txt AC 658 ms 15520 KB
scrambled_17.txt AC 120 ms 2852 KB
scrambled_18.txt AC 699 ms 14888 KB
scrambled_19.txt AC 924 ms 24876 KB
scrambled_20.txt AC 964 ms 24732 KB
scrambled_21.txt AC 610 ms 15000 KB
scrambled_22.txt AC 617 ms 15012 KB
scrambled_23.txt AC 136 ms 3868 KB
scrambled_24.txt AC 265 ms 7196 KB