zoukankan      html  css  js  c++  java
  • Codeforces Gym 100571A A. Cursed Query 离线

    A. Cursed Query
    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/gym/100571/problem/A

    Description

    De Prezer loves movies and series. He has watched the Troy for like 100 times and also he is a big fan of Supernatural series.So, he did some researches and found a cursed object which had n lights on it and initially all of them were turned off.Because of his love to theTroy, he called that object Troy.

    He looked and saw a note on it in Khikulish (language of people of Khikuland): "Ma in hame rah umadim, hala migi ... ? ... Mage man De Prezer am k mikhay mano ... ? .... Man se sale ... To boro .... beshur manam miram ... o mishuram".

    He doesn't know Khikulish, so just ignored the note and tested the Troy.

    He realized that the light number i stays turned on for exactly ai seconds, and then it turns itself off (if it is turned on, in time t, in timet + ai - 1 it will be turned on, but on time t + ai it won't be) and the next light will be turned on (if i < n, next light is the light number i + 1, otherwise it is light with number 1).

    For example if n = 2 and we turn on the first light in time 0, it will be turned on in hole interval [0, a1) and in hole interval [a1, a1 + a2)the second light will be turned on and so on.

    In time 0 he turns on the light number 1.

    De Prezer also loves query.So he gives you q queries.In each query he will give you integer t (the time a revengeful ghost attacked him) and you should print the number of the light that is turned on, in time t.

    Input

    The first line of input contains two integers n and q.

    The second line contains n space separated integers, a1, a2, ..., an .

    The next q lines, each line contains a single integer t .

    1 ≤ n, q ≤ 105

    1 ≤ ai ≤ 109

    1 ≤ t ≤ 1018

    Output

    For each query, print the answer in one line.

    Sample Input

    5 7
    1 2 3 4 5
    1
    2
    3
    7
    14
    15
    16

    Sample Output

    2
    2
    3
    4
    5
    1
    2

    HINT

    题意

    给你一些灯,第一个灯会在[0,a1)的时候亮,第二栈灯会在[a1,a1+a2)的时候亮,然后哒哒哒,循环

    有Q个询问,问你在t秒时,是哪栈灯在亮

    题解

    我是离线做的,但是感觉二分也可以

    代码

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)
    const int maxn=202501;
    #define mod 1000000007
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //*************************************************************************************
    
    ll a[maxn];
    ll sum[maxn];
    struct node
    {
        ll x,y,z;
    };
    node query[maxn];
    bool cmp(node a,node b)
    {
        return a.x<b.x;
    }
    bool cmp1(node a,node b)
    {
        return a.y<b.y;
    }
    int main()
    {
        ll n,q;
        n=read(),q=read();
        for(int i=1;i<=n;i++)
            a[i]=read();
        for(int i=1;i<=n;i++)
            sum[i]+=a[i]+sum[i-1];
        for(int i=1;i<=q;i++)
        {
            query[i].x=read();
            query[i].x%=sum[n];
            query[i].y=i;
        }
        sort(query+1,query+1+q,cmp);
        int j=1;
        for(int i=1;i<=q;i++)
        {
            while(sum[j]<=query[i].x&&j<n)
                j++;
            query[i].z=j;
        }
        sort(query+1,query+1+q,cmp1);
        for(int i=1;i<=q;i++)
            printf("%d
    ",query[i].z);
    }
  • 相关阅读:
    带你破解时间管理的谜题
    学点产品思维(一起拿返现)
    利用MAT玩转JVM内存分析(一)
    JVM利器:Serviceability Agent介绍
    003-005:Java平台相关的面试题
    002-如何理解Java的平台独立性
    001-为什么Java能这么流行
    Redis保证事务一致性,以及常用的数据结构
    敏感词过滤服务的实现
    或许,挂掉的点总是出人意料(hw其实蛮有好感的公司)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4684542.html
Copyright © 2011-2022 走看看