AtCoder Beginner Contest 113 C

C - ID


Time limit : 2sec / Memory limit : 1024MB

Score: 300 points

Problem Statement

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Yi and belongs to Prefecture Pi.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is Pi, and the last six digits of the ID number is x.

Here, if Pi or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

  • 1≤N≤105
  • 1≤M≤105
  • 1≤PiN
  • 1≤Yi≤109
  • Yi are all different.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P1 Y1
:
PM YM

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, …).


Sample Input 1

Copy
2 3
1 32
2 63
1 12

Sample Output 1

Copy
000001000002
000002000001
000001000001
  • As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.
  • As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.
  • As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

Sample Input 2

Copy
2 3
2 55
2 77
2 99

Sample Output 2

Copy
000002000001
000002000002
000002000003

高级点的结构体排序,主要难点是判断每个区间的数字排序
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
//#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1<<31)-1;
#define mem(a) (memset(a,0,sizeof(a)))
struct P{
    int x,y;
}H[200000];
vector<int>G[200000];
int POS(int k,int value){
    int mid;
    int left = 0;
    int len = G[k].size();
    int right = len - 1;
    //cout<<" "<
    while(left <= right){
 
        // 确保中点靠近区间的起点
        mid = left + (right-left)/2;
        //cout<//cout<<"mid= "<// 如果找到则返回
        if(G[k][mid] == value) return mid;
        // 将中点赋给终点
        else if(G[k][mid] > value) right = mid;
        // 将中点加一赋给起点
        else left = mid + 1;
    }
    return -1;
}
set<int>::iterator it;
int main()
{
    set<int>s;
    int N,M;
    int x,y;
    cin>>N>>M;
    for(int i=1;i<=M;i++){
        cin>>x>>y;
        H[i].x = x;
        H[i].y = y;
        G[x].push_back(y);
        s.insert(x);
    }
    for(int i=1;i<=N;i++){
        sort(G[i].begin(),G[i].end());
    }
 
 
    for(int i=1;i<=M;i++){
        cout<6)<'0')<<H[i].x;
        cout<6)<'0')<1<<endl;
    }
    return 0;
}

 



转载于:https://www.cnblogs.com/yinghualuowu/p/9906693.html

你可能感兴趣的:(AtCoder Beginner Contest 113 C)