• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Good Bye 2013 C

C. New Year Ratings Change
time limit per test 1 second
memory limit per test 256 megabytes
 

One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.

There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.

The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.

Help site X cope with the challenging task of rating distribution. Find the optimal distribution.

Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.

If there are multiple optimal solutions, print any of them.

Sample test(s)
Input
3 
5 1 1
Output
5 1 2
Input
1 
1000000000
Output
1000000000
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <stack>
 6 #include <queue>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define INF 0x7fffffff
12 #define mod 1000000007
13 #define ll long long
14 #define maxn 300006
15 #define pi acos(-1.0)                                             
16 #define FF(i,n) for(int i=0;i<n;i++)
17 int n, m, s, z;
18 pair<ll,ll> a[maxn];
19 bool cmp(pair<ll, int>a, pair<ll, int> b){
20     return a.second < b.second;
21 }
22 int main(){
23     scanf("%d",&n);
24     s = 0;
25     for (int i = 0; i < n; i++){
26         scanf("%I64d", &a[i].first);
27         a[i].second = i;
28     }
29     sort(a, a + n);
30     int j=0,l,r;
31     ll m = 0, z = 0;
32     for (int i = 0; i < n; i=j){
33         while (j<n&&a[i].first == a[j].first)j++;
34         l = i; r = j;
35         z = max(0LL, m - a[l].first + 1);
36         for (int k = l; k < r; k++){
37             a[k].first += z;
38             z++;
39         }
40         m = a[r - 1].first;
41     }
42     sort(a, a + n, cmp);
43     for (int i = 0; i < n; i++)printf("%I64d ", a[i].first);
44     return 0;
45 }
View Code
posted @ 2014-01-03 16:28  HaibaraAi  阅读(196)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3