Submission #1358082

#TimeUsernameProblemLanguageResultExecution timeMemory
1358082KALARRYFish 3 (JOI24_fish3)C++20
0 / 100
2094 ms5096 KiB
//chockolateman

#include<bits/stdc++.h>

using namespace std;

const long long INF = 1e15;

int N,D,Q;
long long a[300005];

int main()
{
    scanf("%d%d",&N,&D);
    for(int i = 1 ; i <= N ; i++)
        scanf("%lld",&a[i]);
    scanf("%d",&Q);
    for(int l,r,i = 1 ; i <= Q ; i++)
    {
        scanf("%d%d",&l,&r);
        long long counter = 0;
        bool problem = false;
        long long val = INF;
        for(int j = r ; j >= l ; j--)
        {
            if(a[j] <= val)
                val = a[j];
            else
            {
                long long targ = val/D + a[j]%D;
                if(targ > val)
                    targ -= D;
                if(targ < 0)
                {
                    problem = true;
                    break;
                }
                counter += (a[j] - targ)/D;
                val = targ;
            }
        }
        if(problem)
            printf("-1\n");
        else
            printf("%lld\n",counter);
    }
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d%d",&N,&D);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
Main.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%d%d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...