結果
問題 | No.1347 HS Railway |
ユーザー | PCTprobability |
提出日時 | 2021-01-15 23:19:29 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 3,881 bytes |
コンパイル時間 | 2,606 ms |
コンパイル使用メモリ | 165,888 KB |
実行使用メモリ | 12,160 KB |
最終ジャッジ日時 | 2024-05-05 01:12:47 |
合計ジャッジ時間 | 7,161 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 20 ms
8,576 KB |
testcase_13 | AC | 14 ms
5,376 KB |
testcase_14 | AC | 7 ms
5,376 KB |
testcase_15 | AC | 12 ms
9,216 KB |
testcase_16 | AC | 22 ms
7,296 KB |
testcase_17 | AC | 4 ms
5,376 KB |
testcase_18 | AC | 37 ms
11,008 KB |
testcase_19 | AC | 34 ms
5,888 KB |
testcase_20 | AC | 31 ms
10,240 KB |
testcase_21 | AC | 15 ms
8,192 KB |
testcase_22 | AC | 39 ms
11,392 KB |
testcase_23 | AC | 33 ms
7,040 KB |
testcase_24 | AC | 13 ms
6,144 KB |
testcase_25 | AC | 24 ms
7,424 KB |
testcase_26 | AC | 35 ms
9,216 KB |
testcase_27 | AC | 25 ms
10,496 KB |
testcase_28 | AC | 36 ms
11,188 KB |
testcase_29 | AC | 39 ms
10,624 KB |
testcase_30 | AC | 34 ms
11,264 KB |
testcase_31 | AC | 30 ms
11,392 KB |
testcase_32 | AC | 44 ms
11,904 KB |
testcase_33 | AC | 46 ms
12,032 KB |
testcase_34 | AC | 48 ms
11,904 KB |
testcase_35 | AC | 45 ms
12,032 KB |
testcase_36 | AC | 49 ms
11,904 KB |
testcase_37 | AC | 50 ms
12,152 KB |
testcase_38 | AC | 51 ms
12,032 KB |
testcase_39 | AC | 55 ms
12,152 KB |
testcase_40 | AC | 43 ms
12,032 KB |
testcase_41 | AC | 43 ms
12,032 KB |
testcase_42 | AC | 52 ms
12,032 KB |
testcase_43 | AC | 40 ms
12,160 KB |
testcase_44 | AC | 42 ms
12,160 KB |
testcase_45 | AC | 39 ms
12,156 KB |
testcase_46 | AC | 46 ms
11,904 KB |
testcase_47 | AC | 50 ms
12,032 KB |
testcase_48 | AC | 55 ms
11,904 KB |
testcase_49 | AC | 45 ms
11,904 KB |
testcase_50 | AC | 51 ms
12,032 KB |
testcase_51 | AC | 45 ms
11,904 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define all(s) (s).begin(),(s).end() #define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i] #define rever(vec) reverse(vec.begin(), vec.end()) #define sor(vec) sort(vec.begin(), vec.end()) #define fi first #define se second const ll mod = 998244353; //const ll mod = 1000000007; const ll inf = 2000000000000000000ll; static const long double pi = 3.141592653589793; template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;} template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;} ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; } int main() { /* mod は 1e9+7 */ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(10); ll n; cin>>n; assert(2<=n&&n<=100000); ll a[5][n-1]; for(int i=0;i<5;i++){ for(int j=0;j<n-1;j++){ a[i][j]=0; } } ll f[5][n]; map<ll,ll> w; map<ll,ll> ww; vector<ll> l(5),r(5); for(int i=0;i<5;i++){ cin>>l[i]>>r[i]; assert(1<=l[i]&&l[i]<r[i]&&r[i]<=n&&w[l[i]]==0&&ww[r[i]]==0); w[l[i]]++; ww[r[i]]++; l[i]--; r[i]--; for(int j=l[i];j<=r[i]-1;j++){ cin>>a[i][j]; assert(1<=a[i][j]&&a[i][j]<=100000); if(i!=0&&a[i-1][j]!=0){ assert(a[i-1][j]<a[i][j]); } f[i][j]=0; } f[i][n-1]=0; } for(int i=0;i<5;i++){ for(int j=1;j<n;j++){ f[i][j]=f[i][j-1]+a[i][j-1]; } } ll m; cin>>m; vector<vector<ll>> s(5); for(int i=0;i<m;i++){ ll b,si; cin>>b>>si; assert(1<=b&&b<=5&&1<=si&&si<=1000000); b--; s[b].push_back(si); } for(int i=0;i<5;i++){ sor(s[i]); } ll ans=0; for(int i=4;i>=0;i--){ for(int j=i-1;j>=0;j--){ if(l[i]>r[j]||l[j]>r[i]){ continue; } if(l[i]<=l[j]&&r[j]<=r[i]){ for(int k=0;k<int(s[j].size());k++){ ll b=s[j][k]; ll c=f[j][r[j]]-f[j][l[j]]; ll d=f[i][r[j]]-f[i][l[j]]; // cout<<0<<" "<<i<<" "<<j<<" "<<b<<" "<<d<<" "<<c<<" "<<(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin())<<endl; ans+=(upper_bound(all(s[i]),b-(f[i][l[j]]-f[i][l[i]]))-s[i].begin())-(lower_bound(all(s[i]),b+c-d-(f[i][l[j]]-f[i][l[i]]))-s[i].begin()); } } else if(l[j]<=l[i]&&r[i]<=r[j]){ for(int k=0;k<int(s[j].size());k++){ ll b=s[j][k]+f[j][l[i]]-f[j][l[j]]; ll c=f[j][r[i]]-f[j][l[i]]; ll d=f[i][r[i]]-f[i][l[i]]; // cout<<1<<" "<<i<<" "<<j<<" "<<b<<" "<<d<<" "<<c<<" "<<(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin())<<endl; ans+=(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin()); } } else if(l[i]<=l[j]){ for(int k=0;k<int(s[j].size());k++){ ll b=s[j][k]; ll c=f[j][r[i]]-f[j][l[j]]; ll d=f[i][r[i]]-f[i][l[j]]; // cout<<2<<" "<<i<<" "<<j<<" "<<b<<" "<<d<<" "<<c<<" "<<(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin())<<endl; ans+=(upper_bound(all(s[i]),b-(f[i][l[j]]-f[i][l[i]]))-s[i].begin())-(lower_bound(all(s[i]),b+c-d-(f[i][l[j]]-f[i][l[i]]))-s[i].begin()); } } else if(l[j]<=l[i]){ for(int k=0;k<int(s[j].size());k++){ ll b=s[j][k]+f[j][l[i]]-f[j][l[j]]; ll c=f[j][r[j]]-f[j][l[i]]; ll d=f[i][r[j]]-f[i][l[i]]; // cout<<3<<" "<<i<<" "<<j<<" "<<b<<" "<<d<<" "<<c<<" "<<(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin())<<endl; ans+=(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin()); } } } } cout<<ans<<endl; }