QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#601924 | #9370. Gambling on Choosing Regionals | wanghanshi_1999 | RE | 2ms | 11280kb | C++14 | 1.8kb | 2024-09-30 16:03:42 | 2024-09-30 16:03:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
struct node
{
int num;
};
node tree[4*maxn];
int c[maxn],id,res = 1e9+10,a[maxn],b[maxn];
string s[maxn];
map<string,int> mp;
map<int,int> mp1;
vector<int>v[maxn];
int ans[maxn],last[maxn];
bool vis[maxn];
void pushup(int root)
{
tree[root].num = tree[root<<1].num + tree[root<<1|1].num;
}
void update(int root,int l,int r,int x,int k)
{
if(l == r)
{
tree[root].num += k;
return;
}
int mid = (l+r) >> 1;
if(x <= mid) update(root<<1,l,mid,x,k);
else update(root<<1|1,mid+1,r,x,k);
pushup(root);
}
int query(int root,int l,int r,int x)
{
if(l == r)
return 1;
int mid = (l+r) >> 1;
if(x <= mid) return query(root<<1,l,mid,x) + tree[root<<1|1].num;
else return query(root<<1|1,mid+1,r,x);
}
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i = 1;i <= k;i++)
scanf("%d",&c[i]),res = min(res,c[i]);
for(int i = 1;i <= n;i++)
{
int x;
cin >> x >> s[i];
if(mp.find(s[i]) == mp.end())
mp[s[i]] = ++id;
v[mp[s[i]]].push_back(x);
a[i] = x;
b[i] = x;
}
sort(a+1,a+n+1);
for(int i = 1;i <= id;i++)
{
sort(v[i].begin(),v[i].end(),greater<int>());
int len = v[i].size();
int j;
for(j = 0;j < min(res,len);j++)
{
int x = lower_bound(a+1,a+n+1,v[i][j]) - a;
update(1,1,n,x,1);
vis[v[i][j]] = 1;
}
last[i] = v[i][j-1];
}
for(int i = 1;i <= n;i++)
{
if(vis[b[i]])
{
// cout << "------" << b[i] << endl;
int x = lower_bound(a+1,a+n+1,b[i]) - a;
printf("%d\n",query(1,1,n,x));
}
else
{
int id1 = lower_bound(a+1,a+n+1,last[mp[s[i]]]) - a;
int id2 = lower_bound(a+1,a+n+1,b[i]) - a;
update(1,1,n,id1,-1);
update(1,1,n,id2,1);
printf("%d\n",query(1,1,n,id2));
update(1,1,n,id1,1);
update(1,1,n,id2,-1);
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11280kb
input:
5 3 1 2 3 100 THU 110 PKU 95 PKU 105 THU 115 PKU
output:
2 1 2 2 1
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 10344kb
input:
5 2 2 3 100 THU 110 PKU 95 PKU 105 THU 115 PKU
output:
4 2 4 3 1
result:
ok 5 lines
Test #3:
score: -100
Runtime Error
input:
100000 100000 57148 51001 13357 71125 98369 67226 49388 90852 66291 39573 38165 97007 15545 51437 89611 41523 27799 15529 16434 44291 47134 90227 26873 52252 41605 21269 9135 55784 70744 17563 79061 73981 70529 35681 91073 52031 23811 79501 1607 46365 76868 72137 71041 29217 96749 46417 40199 55907 ...