Submission #1110189

#TimeUsernameProblemLanguageResultExecution timeMemory
1110189vjudge1Fish 3 (JOI24_fish3)C++17
9 / 100
2059 ms112556 KiB
#include <bits/stdc++.h>
using namespace std;

#define ff(i, a, b) for(auto i=(a); i<=(b); ++i)
#define ffr(i, b, a) for(auto i=(b); i>=(a); --i)
#define nl "\n"
#define ss " "
#define pb push_back
#define fi first
#define se second
#define sz(s) (int)s.size()
#define ms(a,x) memset(a, x, sizeof (a))
#define re exit(0)
#define cn continue

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


const int mod=1e9+7;
//const int mod=998244353;
const int maxn=1e5+105;
const int maxm=4*maxn+5;
const ll inf=1e18;

mt19937 ran(time(0));
mt19937_64 ran64(time(0));

void rf(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen("o.inp","r")){
        freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
    }
}

void add(int &x, int y)
{
    x+=y;
    if(x>=mod) x-=mod;
    if(x<0) x+=mod;
}

int n, q;
ll d, c[maxn];

signed main()
{
    rf();
    cin>>n>>d;
    ff(i, 1, n) cin>>c[i];
    cin>>q;
    while(q--)
    {
        int l, r; cin>>l>>r;
        ll x=inf, ans=0;
        bool ok=1;
        ffr(i, r, l)
        {
            if(c[i]>x)
            {
                ll s=(c[i]-x+d-1)/d;
                if(c[i]<d*s)
                {
                    ok=0; break;
                }
                x=c[i]-s*d;
                ans+=s;
            }
            else x=c[i];
        }
        if(!ok) ans=-1;
        cout<<ans<<nl;
    }
    re;
}

Compilation message (stderr)

Main.cpp: In function 'void rf()':
Main.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:41:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
#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...