답안 #44602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44602 2018-04-03T18:59:34 Z PowerOfNinjaGo Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
1165 ms 20924 KB
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii;
#define X first
#define Y second
#define pb push_back
int n, q;
const int maxn = 5e5+5;
int arr[maxn];
int mx[maxn];
int team[maxn];
int rng[maxn];
ll intv[maxn];
ll dx[maxn];
vector<int> cap;
ll getPos(int id, int t)
{
    int cap = team[id];
    int rnd = t/intv[cap];
    ll res = -id;
    res += rnd*dx[cap];
    //printf("getPos(%d, %d) = %lld\n", id, t, res);
    return res;
}
int cnt(ll x, int t)
{
    int lo = 1, hi = n+1;
    while(lo< hi)
    {
        int mid = (lo+hi)/2;
        if(getPos(mid, t)<= x) hi = mid;
        else lo = mid+1;
    }
    //printf("end %d\n", lo);
    return n+1-lo;
}
int main()
{
    scanf("%d %d", &n, &q);
    for(int i = 1; i<= n; i++) scanf("%d", &arr[i]);
    for(int i = 1; i<= n; i++)
    {
        if(arr[i]> mx[i-1])
        {
            mx[i] = arr[i];
            rng[i] = 1;
            team[i] = i;
            cap.pb(i);
        }
        else
        {
            mx[i] = mx[i-1];
            rng[i] = rng[i-1]+1;
            team[i] = team[i-1];
        }
    }
    for(int i = 0; i< (int) cap.size(); i++)
    {
        int x = cap[i];
        if(i == 0) intv[x] = arr[x], dx[x] = arr[x];
        else
        {
            int w = cap[i-1];
            int rnd = (arr[x]+dx[w]-1)/dx[w];
            intv[x] = intv[w]*rnd;
            dx[x] = dx[w]*rnd;
        }
    }
    while(q--)
    {
        ll x, y, t; scanf("%lld %lld %lld", &t, &x, &y);
        int res = cnt(y, t)-cnt(x-1, t);
        if(x<= t && t<= y) res++;
        printf("%d\n", res);
    }
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
worst_reporter3.cpp:42:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i<= n; i++) scanf("%d", &arr[i]);
                                ~~~~~^~~~~~~~~~~~~~~
worst_reporter3.cpp:73:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         ll x, y, t; scanf("%lld %lld %lld", &t, &x, &y);
                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 952 ms 11224 KB Output is correct
2 Correct 963 ms 11292 KB Output is correct
3 Correct 1006 ms 11420 KB Output is correct
4 Correct 958 ms 11432 KB Output is correct
5 Correct 1004 ms 11432 KB Output is correct
6 Correct 996 ms 11432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 11432 KB Output is correct
2 Correct 3 ms 11432 KB Output is correct
3 Correct 3 ms 11432 KB Output is correct
4 Correct 3 ms 11432 KB Output is correct
5 Correct 3 ms 11432 KB Output is correct
6 Correct 3 ms 11432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 952 ms 11224 KB Output is correct
2 Correct 963 ms 11292 KB Output is correct
3 Correct 1006 ms 11420 KB Output is correct
4 Correct 958 ms 11432 KB Output is correct
5 Correct 1004 ms 11432 KB Output is correct
6 Correct 996 ms 11432 KB Output is correct
7 Correct 3 ms 11432 KB Output is correct
8 Correct 3 ms 11432 KB Output is correct
9 Correct 3 ms 11432 KB Output is correct
10 Correct 3 ms 11432 KB Output is correct
11 Correct 3 ms 11432 KB Output is correct
12 Correct 3 ms 11432 KB Output is correct
13 Correct 682 ms 11432 KB Output is correct
14 Correct 669 ms 11432 KB Output is correct
15 Correct 685 ms 11432 KB Output is correct
16 Correct 646 ms 11432 KB Output is correct
17 Correct 929 ms 20796 KB Output is correct
18 Correct 943 ms 20800 KB Output is correct
19 Correct 931 ms 20800 KB Output is correct
20 Correct 921 ms 20800 KB Output is correct
21 Correct 941 ms 20800 KB Output is correct
22 Correct 966 ms 20924 KB Output is correct
23 Correct 910 ms 20924 KB Output is correct
24 Correct 982 ms 20924 KB Output is correct
25 Correct 985 ms 20924 KB Output is correct
26 Correct 980 ms 20924 KB Output is correct
27 Correct 859 ms 20924 KB Output is correct
28 Correct 974 ms 20924 KB Output is correct
29 Correct 1165 ms 20924 KB Output is correct
30 Correct 937 ms 20924 KB Output is correct
31 Correct 1098 ms 20924 KB Output is correct
32 Correct 772 ms 20924 KB Output is correct
33 Correct 2 ms 20924 KB Output is correct