QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#223264#7586. Three InvestigatorsPhantomThresholdAC ✓1364ms19280kbC++201.3kb2023-10-21 23:09:082023-10-21 23:09:10

Judging History

你现在查看的是最新测评结果

  • [2023-10-21 23:09:10]
  • 评测
  • 测评结果:AC
  • 用时:1364ms
  • 内存:19280kb
  • [2023-10-21 23:09:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
struct YT
{
	map<int,long long> mp[7]; //mp[a]=pos: consecutive a's starting at pos
	YT()
	{
		for(int r=1;r<=5;r++)
			mp[r][inf]=0;
	}
	void insert(int r,int val,int cnt)
	{
		if(r>5)return;
		auto it=mp[r].upper_bound(val);
		long long pos=it->second;
		if(not mp[r].contains(val))mp[r][val]=pos;
		while(1)
		{
//			cerr<<"insert "<<r<<' '<<val<<' '<<cnt<<' ';
//			if(it!=mp[r].end())cerr<<' '<<it->first<<' '<<it->second<<endl;
//			else {cerr<<"fuck "<<endl;assert(0);}
			if(it->first==inf)
			{
				it->second=pos+cnt;
				return;
			}
			if(it->second<=pos+cnt)
			{
				if(next(it)->second<=pos+cnt)
				{
					insert(r+1,it->first,next(it)->second-it->second);
					it=mp[r].erase(it);
				}
				else
				{
					if(it->second!=pos+cnt)insert(r+1,it->first,pos+cnt-it->second);
					it->second=pos+cnt;
					return;
				}
			}
		}
	}
	long long query()
	{
		long long ret=0;
		for(int r=1;r<=5;r++)
			ret+=mp[r][inf];
		return ret;
	}
};
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		YT t;
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			int x;
			cin>>x;
			t.insert(1,x,x);
			cout<<t.query()<<" \n"[i==n];
		}
		if(T%10==0)cout<<flush;
	}
	
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

input:

1
8
8 7 6 5 1 3 2 4

output:

8 15 21 26 27 30 30 34

result:

ok 8 numbers

Test #2:

score: 0
Accepted
time: 1364ms
memory: 19280kb

input:

1005
100
5 2 9 6 6 6 3 8 4 5 9 10 2 7 10 4 7 3 1 4 2 5 1 6 8 7 8 5 9 3 8 2 1 4 2 8 7 9 9 8 8 6 5 8 3 4 9 5 3 8 6 8 4 2 10 1 9 9 1 1 8 5 2 4 4 2 3 6 7 8 3 9 6 1 7 1 4 1 8 8 9 7 4 9 8 3 10 6 5 8 8 10 6 2 9 6 9 3 10 6
100
7 2 9 6 2 5 6 1 5 2 7 5 4 9 10 8 1 7 6 4 9 7 1 1 1 7 2 8 7 4 3 6 8 3 7 3 3 9 2 9 ...

output:

5 7 16 22 28 34 37 45 49 54 63 73 75 82 92 96 103 106 106 110 110 115 115 121 129 136 144 149 158 158 166 166 166 168 168 176 183 192 201 209 217 223 223 231 231 231 240 244 244 252 258 266 268 268 278 278 287 296 296 296 304 309 309 309 312 312 312 318 325 333 333 342 348 348 355 355 355 355 363 37...

result:

ok 500000 numbers