码迷,mamicode.com
首页 > 其他好文 > 详细

gym/102091

时间:2019-02-17 00:50:51      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:lap   题意   enc   splay   pll   iterator   cin   boost   stream   

https://codeforces.com/gym/102091

2018-2019 ACM-ICPC, Asia Nakhon Pathom Regional Contest

 

 

K

# 题意
有n个事物会出现在河流中,每个事物会出现于le到ri秒。问第i秒第K小是多少。保证le和i在出现顺序中是递增的。
# 思路
先离散化,然后开一个树状数组,出现了的事物就插入权值树状数组,并记下消失的时间ri,等查询操作前把消失的事物清除。 
技术图片
#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>

/*
        
⊂_ヽ
  \\ Λ_Λ  来了老弟
   \(‘?‘)
    > ⌒ヽ
   /   へ\
   /  / \\
   ? ノ   ヽ_つ
  / /
  / /|
 ( (ヽ
 | |、\
 | 丿 \ ⌒)
 | |  ) /
‘ノ )  L?

*/

using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue



typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl ‘\n‘

#define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);


const ll oo = 1ll<<17;
const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18
const int mod = 1e9+7;
const double esp = 1e-8;
const double PI=acos(-1.0);
const double PHI=0.61803399;    //黄金分割点
const double tPHI=0.38196601;


template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<0||ch>9) f|=(ch==-),ch=getchar();
    while (ch>=0&&ch<=9) x=x*10+ch-0,ch=getchar();
    return x=f?-x:x;
}
struct FastIO {
    static const int S = 4e6;
    int wpos;
    char wbuf[S];
    FastIO() : wpos(0) {}
    inline int xchar() {
        static char buf[S];
        static int len = 0, pos = 0;
        if (pos == len)
            pos = 0, len = fread(buf, 1, S, stdin);
        if (pos == len) exit(0);
        return buf[pos++];
    }
    inline int xuint() {
        int c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        for (; 0 <= c && c <= 9; c = xchar()) x = x * 10 + c - 0;
        return x;
    }
    inline int xint()
    {
        int s = 1, c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        if (c == -) s = -1, c = xchar();
        for (; 0 <= c && c <= 9; c = xchar()) x = x * 10 + c - 0;
        return x * s;
    }
    inline void xstring(char *s)
    {
        int c = xchar();
        while (c <= 32) c = xchar();
        for (; c > 32; c = xchar()) * s++ = c;
        *s = 0;
    }
    inline void wchar(int x)
    {
        if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0;
        wbuf[wpos++] = x;
    }
    inline void wint(int x)
    {
        if (x < 0) wchar(-), x = -x;
        char s[24];
        int n = 0;
        while (x || !n) s[n++] = 0 + x % 10, x /= 10;
        while (n--) wchar(s[n]);
        wchar(\n);
    }
    inline void wstring(const char *s)
    {
        while (*s) wchar(*s++);
    }
    ~FastIO()
    {
        if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0;
    }
} io;   
inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;}

/*-----------------------showtime----------------------*/

            const int maxn = 1e6+9;
            vector<int>v;
            int getid(int x){
                return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;
            }
            struct ask
            {
                int op;
                int a,b,c;
            }e[maxn];
            int sum[maxn];
            int lowbit(int x){
                return x & (-x);
            }
            void add(int x,int c){
                while(x < maxn){
                    sum[x] += c;
                    x = x + lowbit(x);
                }
            }
            int cal(int x){
                int res = 0;
                while(x > 0){
                    res += sum[x];
                    x -= lowbit(x);
                }
                return res;
            }
            vector<int>er[maxn];

int main(){
            int T,n;  //scanf("%d", &T);
            T = io.xint();
            rep(cas, 1, T){
                printf("Case %d:\n", cas);
                // scanf("%d", &n);
                n = io.xint();
                v.clear();
                for(int i=0; i<maxn; i++) er[i].clear();
                memset(sum, 0, sizeof(sum));
                rep(i, 1, n) {
                    // scanf("%d", &e[i].op);
                    e[i].op = io.xint();
                    if(e[i].op == 1) {
                        // scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c);
                        e[i].a = io.xint(); e[i].b = io.xint(); e[i].c = io.xint();
                        v.pb(e[i].a),v.pb(e[i].c);
                    }
                    else {
                        // scanf("%d%d", &e[i].a, &e[i].b);
                        e[i].a = io.xint(); e[i].b = io.xint();
                        v.pb(e[i].a);
                    }
                }
                sort(v.begin(), v.end());
                v.erase(unique(v.begin(), v.end()), v.end());
                int la = 0;
                rep(i, 1, n){
                    
                    if(e[i].op == 1) {
                        add(e[i].b, 1);
                        int t = getid(e[i].c);
                        er[t+1].pb(e[i].b);
                    }
                    else {
                        for(int k=la; k <= getid(e[i].a); k++)
                            for(int j=0; j<er[k].size(); j++){
                                add(er[k][j], -1);
                            }
                        la = getid(e[i].a)+1;
                        int res = -1, le = 1, ri = maxn-1;  

                        while(le <= ri){
                            int mid = (le + ri) >> 1;
                            if(cal(mid) >= e[i].b) {res = mid, ri = mid - 1;}
                            else le = mid + 1;
                        }
                        if(res == -1) puts("-1");
                        else printf("%d\n", res);
                    }
                } 

            }

            return 0;
}
View Code

 

gym/102091

标签:lap   题意   enc   splay   pll   iterator   cin   boost   stream   

原文地址:https://www.cnblogs.com/ckxkexing/p/10389906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!