QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#596823#9223. Data Determinationucup-team1074TL 332ms43708kbC++232.5kb2024-09-28 16:31:092024-09-28 16:31:10

Judging History

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

  • [2024-09-28 16:31:10]
  • 评测
  • 测评结果:TL
  • 用时:332ms
  • 内存:43708kb
  • [2024-09-28 16:31:09]
  • 提交

answer

// Problem: G - Data Determination
// Contest: Virtual Judge - The 3rd Universal Cup. Stage 8: Cangqian + The 3rd Universal Cup. Stage 7: Warsaw
// URL: https://vjudge.net/contest/658753#problem/G
// Memory Limit: 1014 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
#define int long long
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
void solve() 
{
	int n , k , m;
	cin >> n >> k >> m;
	int ok = 0;
	set<int>st;
	int a[n];
	for(int i = 0 ; i < n ; i ++){
		cin >> a[i];	
		st.insert(a[i]);
	}
	map<int,int>mp;
	map<int,int>pm;
	int id = 0;
	for(auto it : st){
		mp[it] = ++id;
		pm[id] = it;
	}
	vector<int>cnt(id + 5 , 0);
	vector<int>pre(id + 5 , 0);
	int b[n];
	for(int i = 0 ; i < n ; i ++){
		b[i] = mp[a[i]];
	}
	int t = mp[m];
	for(int i = 0 ; i < n ; i++){
		pre[b[i]]++;
		cnt[b[i]]++;
	}
	for(int i = 1 ; i <= id ; i ++){
		pre[i] += pre[i - 1];
	}
	if(k & 1){
		int le = k / 2;
		int ri = k / 2;
		if(!mp.count(m)){
			cout << "NIE\n";
		}
		else{
			if(pre[mp[m] - 1] < le){
				cnt[t] -= le - pre[t - 1];
			}
			if(pre[id] - pre[mp[m]] < ri){
				cnt[t] -= ri - pre[id] + pre[t];
			}
			if(cnt[t] > 0){
				cout <<"TAK\n";
			}
			else{
				cout <<"NIE\n";
			}
		}
	}
	else{
		int l = 1 , r = id;
		while(l <= r){
			while(l < r && pm[l] + pm[r] < m * 2){
				l++;
			}
			if(pm[l] + pm[r] > m * 2){
				r--;
				continue;
			}
			else if(pm[l] + pm[r] == m * 2){
				int le = k / 2 - 1;
				int ri = k / 2 - 1;
				int ok = 1;
				if(l == r){
					if(	cnt[l] < 2 + max(0LL , le - pre[l - 1]) + max(0LL , ri - pre[id] + pre[r])){
						ok = 0;
					}
				}
				if(pre[l - 1] < le){
					if(cnt[l] <= le - pre[l - 1]){
						ok = 0;
					}
				}
				if(pre[id] - pre[r] < ri){
					if(cnt[r] <= ri - pre[id] + pre[r]){
						ok = 0;
					}
				}
				if(ok){
					cout << "TAK\n";
					return;
				}
			}
			else{
				l++;	
			}
		}
		cout <<"NIE\n";
	}
}            
signed main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    int t=1;
	cin>>t;
    while(t--)
    {
    	solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
6 4 42
41 43 41 57 41 42
4 2 4
1 2 5 8
7 5 57
101 2 42 5 57 7 13

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 332ms
memory: 43708kb

input:

1
200000 2 482043846
410684388 380438852 309193412 468460689 586281084 680820569 266819813 639025900 488292166 503516930 532292185 618277661 728546481 628339224 673945619 471325257 372807753 325778059 372151033 548358519 276494019 336701079 320784795 377493322 385262271 621712987 349634764 668994576...

output:

NIE

result:

ok single line: 'NIE'

Test #3:

score: -100
Time Limit Exceeded

input:

10
20000 3530 502140211
367996343 553577602 581694419 435810361 532394401 431613294 485360190 608191058 506969937 531905607 429252296 360241499 519031654 250454430 478548102 753825992 450326073 603766643 566036856 511634983 416622101 753825992 753825992 380511285 390746506 436237616 342529443 878920...

output:


result: