結果
| 問題 |
No.1347 HS Railway
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-01-16 14:23:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 972 bytes |
| コンパイル時間 | 2,480 ms |
| コンパイル使用メモリ | 198,012 KB |
| 最終ジャッジ日時 | 2025-01-17 22:46:46 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 50 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | int N; scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%d%d",&L[k],&R[k]); L[k]--; R[k]--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:17:70: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | rep(i,N) A[k][i]=0; for(int i=L[k]+1; i<=R[k]; i++){ int a; scanf("%d",&a); A[k][i]=A[k][i-1]+a; }
| ~~~~~^~~~~~~~~
main.cpp:20:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf("%d",&Q);
| ~~~~~^~~~~~~~~
main.cpp:21:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | rep(i,Q){ int b,s; scanf("%d%d",&b,&s); b--; S[b].push_back(s); }
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int N;
int L[5],R[5];
LL A[5][100000];
int Q;
vector<int> S[5];
int main(){
int N; scanf("%d",&N);
rep(k,5){
scanf("%d%d",&L[k],&R[k]); L[k]--; R[k]--;
rep(i,N) A[k][i]=0; for(int i=L[k]+1; i<=R[k]; i++){ int a; scanf("%d",&a); A[k][i]=A[k][i-1]+a; }
}
scanf("%d",&Q);
rep(i,Q){ int b,s; scanf("%d%d",&b,&s); b--; S[b].push_back(s); }
rep(k,5) sort(S[k].begin(),S[k].end());
LL ans=0;
rep(k2,5) rep(k1,k2){
LL maxL=max(L[k1],L[k2]), minR=min(R[k1],R[k2]);
if(minR<maxL) continue;
// S[k1]-S[k2]
LL l=A[k2][maxL]-A[k1][maxL],r=A[k2][minR]-A[k1][minR];
int lp=0,rp=0;
for(int s:S[k1]){
while(lp<S[k2].size()) if(s-S[k2][lp]>=l) lp++; else break;
while(rp<S[k2].size()) if(s-S[k2][rp]>r) rp++; else break;
ans+=lp-rp;
}
}
printf("%lld\n",ans);
return 0;
}
Nachia