zoukankan      html  css  js  c++  java
  • CodeForces 159c String Manipulation 1.0

    String Manipulation 1.0

    Time Limit: 3000ms
    Memory Limit: 262144KB
    This problem will be judged on CodeForces. Original ID: 159C
    64-bit integer IO format: %I64d      Java class name: (Any)

    One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of character c from the name. After the user changed his name, he can't undo the change.

    For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc".

    Polycarpus learned that some user initially registered under nickname t, where t is a concatenation of k copies of string s. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name.

     

    Input

    <p< p="">

    The first line contains an integer k (1 ≤ k ≤ 2000). The second line contains a non-empty string s, consisting of lowercase Latin letters, at most 100characters long. The third line contains an integer n (0 ≤ n ≤ 20000) — the number of username changes. Each of the next n lines contains the actual changes, one per line. The changes are written as "pi ci" (without the quotes), where pi (1 ≤ pi ≤ 200000) is the number of occurrences of letter cici is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1.

     

    Output

    <p< p="">

    Print a single string — the user's final name after all changes are applied to it.

     

    Sample Input

    <p< p=""><p< p="">
    Input
    2
    bac
    3
    2 a
    1 b
    2 c
    Output
    acb
    Input
    1
    abacaba
    4
    1 a
    1 a
    1 c
    2 b
    Output
    baa

    Hint

    <p< p="">

    Let's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb".

     

    Source

     
    解题:直接用线段树记录二十六个字母分别的出现位置。。。
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 200010;
     4 int tree[26][maxn<<2],k,n,p;
     5 bool isdel[maxn];
     6 string str,s,c;
     7 void pushup(int wd,int v) {
     8     tree[wd][v] = tree[wd][v<<1] + tree[wd][v<<1|1];
     9 }
    10 void update(int L,int R,int wd,int id,int v) {
    11     if(L == R) {
    12         tree[wd][v]++;
    13         return;
    14     }
    15     int mid = (L + R)>>1;
    16     if(id <= mid) update(L,mid,wd,id,v<<1);
    17     if(id > mid) update(mid+1,R,wd,id,v<<1|1);
    18     pushup(wd,v);
    19 }
    20 void del(int L,int R,int wd,int v,int rk){
    21     if(L == R) {
    22         tree[wd][v]--;
    23         isdel[L] = true;
    24         return;
    25     }
    26     int mid = (L + R)>>1;
    27     if(tree[wd][v<<1] >= rk) del(L,mid,wd,v<<1,rk);
    28     else del(mid+1,R,wd,v<<1|1,rk-tree[wd][v<<1]);
    29     pushup(wd,v);
    30 }
    31 int main() {
    32     cin.sync_with_stdio(false);
    33     cin>>k>>s>>n;
    34     str = "";
    35     for(int i = 0; i < k; ++i) str += s;
    36     int len = str.length();
    37     for(int  i = 0; i < len; ++i)
    38         update(0,len-1,str[i]-'a',i,1);
    39     while(n--){
    40         cin>>p>>c;
    41         del(0,len-1,c[0]-'a',1,p);
    42     }
    43     for(int i = 0; i < len; ++i)
    44         if(!isdel[i]) cout<<str[i];
    45     cout<<endl;
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    AppScan安全问题解决方案
    WPF方法 获取控件在屏幕的位置和自动控件位置
    WPF获取鼠标点击位置和API使用
    system.windows.controls
    .net 获取项目的根目录
    InvokeRequired
    控件取图片和矩形框 小测试
    mariadb 设置远程访问
    代码生成器 链接
    分享个网站
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4440076.html
Copyright © 2011-2022 走看看