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

Codeforces46D--区间查询

时间:2014-09-09 10:31:08      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   div   sp   

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

typedef short int int16;///32767
typedef int int32;///2147483647
typedef long long int64;///9223372036854775807
const double PI=acos(-1.0);///3.141593
const long long MOD=(long long)1E9+7LL;///1000000007
int isdigit(int c);int islower(int c);int isupper(int c);
int tolower(int c);int toupper(int c);
template <class T> T Susake_pow(T a,T b)///pow
{T res;if(b==0) return 1;else while((b&1)==0){b>>=1;a*=a;}res=a;b>>=1;while(b!=0){a*=a;if((b&1)!=0)res*=a;b>>=1;}return res;}
template<class T> inline T gcd(T a,T b)///gcd
{if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b)///lcm
{if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template<class T> inline char *Susake_nsystem(T n)///itoa(26)
{T t=0,i;char *s,*p;s=(char *)malloc(sizeof(char)*1000);p=(char *)malloc(sizeof(char)*1000);
while(n){s[t]=n%26+64;if(s[t]==64){s[t]+=26;n-=26;}t++;n/=26;}s[t]=\0;for(i = 0; i < t; i++)p[i]=s[t-1-i];p[i]=\0;free(s);return p;}
int Susake_system(char *s)///atoi(26)
{int len=strlen(s),i,sum=0;char p[1000];for(i=0;i<len;i++)p[i]=s[len-1-i]-64;for(i=0;i<len;i++)sum+=p[i]*Susake_pow(26,i);return sum;}
int fa[1];
template <class T> T union_find(T x)///union_find
{return fa[x] == x ? x : fa[x] = union_find(fa[x]);}

const int INF = 1000000000;

int main() {
    int L, B, F, n, a[128], b[128];
    std::pair<int, int> p[128];
    std::vector<std::pair<int, int> > v;

    scanf("%d%d%d", &L, &F, &B);
    v.push_back(std::make_pair(-INF, -F));
    v.push_back(std::make_pair(L + B, INF));
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &a[i], &b[i]);
        if (a[i] == 2) {
            v.erase(find(v.begin(), v.end(), p[b[i]]));
        } else {
            p[i].first = -1;
            for (int j = 1; j < (int)v.size(); ++j) {
                if (v[j - 1].second + F + b[i] + B <= v[j].first) {
                    p[i] = std::make_pair(v[j - 1].second + F, v[j - 1].second + F + b[i]);
                    v.push_back(p[i]);
                    sort(v.begin(), v.end());
                    break;
                }
            }
            printf("%d\n", p[i].first);
        }
    }
    return 0;
}

 

Codeforces46D--区间查询

标签:style   blog   color   os   io   ar   for   div   sp   

原文地址:http://www.cnblogs.com/Susake/p/3961193.html

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