結果

問題 No.3389 k-Days Later
コンテスト
ユーザー GhostMFC
提出日時 2025-12-01 13:33:02
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,924 ms
コンパイル使用メモリ 195,384 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-01 13:33:17
合計ジャッジ時間 15,033 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define inf 0x7fffffff
#define llinf 0x7fffffffffffffff
#define F(a,b,c,d) for(int b=c;b<=d;b+=a)
#define F2(a,b,c,d) for(int b=c;b>=d;b-=a)
#define PRC(b,a) fixed<<setprecision(a)<<b
#define pb push_back
#define All(x) x.begin(),x.end()
#define Next(a,b) for(int a=head[b];a;a=edge[a].nxt)
#define IOS ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
inline ll q_2(ll xx){return xx*xx;}
inline ll Gcd(ll xx,ll yy){return yy?Gcd(yy,xx%yy):xx;}
inline ll q_Pow(ll xx,ll yy,ll pp){ll oo=1;for(;yy;yy>>=1,xx=xx*xx%pp)yy&1?oo=oo*xx%pp:0;return oo;}
inline void Cout(){cout<<endl;}
template <class T1,class...T2>
inline void Cout(T1 x,T2 ...y){cout<<x<<' ';Cout(y...);}
template <typename T> inline void sMin(T &xx,T yy){xx=(xx<yy)?xx:yy;}
template <typename T> inline void sMax(T &xx,T yy){xx=(xx>yy)?xx:yy;}

const int N=100010;

int n,q;
ll D[N];

signed main(){
  IOS
  cin>>n;
  for(int i=1;i<=n;++i)
    cin>>D[i],D[i]+=D[i-1];
  cin>>q;
  while(q--){
    ll y,m,d,k;
    cin>>y>>m>>d>>k;
    y+=k/D[n]; k%=D[n];
    if(D[n]-D[m-1]-d<k){
      k-=(D[n]-D[m-1]-d);
      int l=1,r=n;
      while(l<r){
        int mid=(l+r)>>1;
        if(D[mid]>=k) r=mid;
        else l=mid+1;
      }
      cout<<y+1<<' '<<l<<' '<<k-D[l-1]<<'\n';
    } else{
      if(D[m]-D[m-1]-d>=k){
        cout<<y<<' '<<m<<' '<<d+k<<'\n';
        continue;
      }
      k-=(D[m]-D[m-1]-d);
      ++m;
      int l=m,r=n;
      while(l<r){
        int mid=(l+r)>>1;
        if(D[mid]-D[m-1]>=k) r=mid;
        else l=mid+1;
      }
      cout<<y<<' '<<l<<' '<<k-D[l-1]+D[m-1]<<'\n';
    }
  }
  
  return 0;
}
0