Submission #63097428
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> ppi;
typedef pair<ll,ppi> pppi;
typedef pair<ll,pppi> ppppi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
#define BS(A,x) binary_search(ALL(A),x)
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) (UB(A,x)-LB(A,x))
#define sz(c) ((ll)(c).size())
/*
#include<boost/multiprecision/cpp_int.hpp>
namespace mp=boost::multiprecision;
using Bint=mp::cpp_int;
*/
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>p){os<<p.F<<" "<<p.S;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.F>>p.S;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>v){REP(i,sz(v))os<<v[i]<<(i+1!=sz(v)?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
ld dist(ld x1,ld y1,ld x2,ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
const ld EPS=1e-8;
//*
using mint=modint998244353;
const ll mod=998244353;
//*/
/*
using mint=modint1000000007;
const ll mod=1000000007;
//*/
//using mint=modint;
//*
typedef vector<mint> vm;
typedef vector<vm> vvm;
typedef vector<vvm> vvvm;
typedef vector<vvvm> vvvvm;
ostream&operator<<(ostream&os,mint a){os<<a.val();return os;}
istream&operator>>(istream&is,mint&a){int x;is>>x;a=mint(x);return is;}
//*/
int main(){
ll N;cin>>N;
vi W(N);cin>>W;
vi L(N),R(N);
REP(i,N)cin>>L[i]>>R[i];
segtree<ll,[](ll a,ll b){return min(a,b);},[](){return 1e18;}>segl(2*N+1),segr(2*N+1);
REP(i,N)segl.set(L[i],min(W[i],segl.get(L[i])));
REP(i,N)segr.set(R[i],min(W[i],segr.get(R[i])));
ll Q;cin>>Q;
while(Q--){
ll s,t;cin>>s>>t;s--;t--;
if(L[s]>L[t]||(L[s]==L[t]&&R[s]>R[t]))swap(s,t);
if(R[s]<L[t]){cout<<W[s]+W[t]<<endl;continue;}
ll ans=W[s]+W[t]+min(segl.prod(max(R[s],R[t])+1,2*N+1),segr.prod(0,L[s]));
if(R[s]>=R[t]||L[s]==L[t]){
if(ans>1e17)ans=-1;
cout<<ans<<endl;
continue;
}
chmin(ans,W[s]+W[t]+segl.prod(R[s]+1,2*N+1)+segr.prod(0,L[t]));
if(ans>1e17)ans=-1;
cout<<ans<<endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Complement Interval Graph |
User |
TKTYI |
Language |
C++ 23 (gcc 12.2) |
Score |
700 |
Code Size |
2953 Byte |
Status |
AC |
Exec Time |
467 ms |
Memory |
27352 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt |
All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt |
Case Name |
Status |
Exec Time |
Memory |
000.txt |
AC |
425 ms |
27264 KB |
001.txt |
AC |
370 ms |
27348 KB |
002.txt |
AC |
382 ms |
27204 KB |
003.txt |
AC |
452 ms |
27256 KB |
004.txt |
AC |
457 ms |
27284 KB |
005.txt |
AC |
433 ms |
27292 KB |
006.txt |
AC |
402 ms |
27228 KB |
007.txt |
AC |
447 ms |
27336 KB |
008.txt |
AC |
382 ms |
27300 KB |
009.txt |
AC |
305 ms |
14500 KB |
010.txt |
AC |
236 ms |
16136 KB |
011.txt |
AC |
231 ms |
25664 KB |
012.txt |
AC |
183 ms |
4720 KB |
013.txt |
AC |
194 ms |
16468 KB |
014.txt |
AC |
452 ms |
27276 KB |
015.txt |
AC |
450 ms |
27248 KB |
016.txt |
AC |
467 ms |
27084 KB |
017.txt |
AC |
448 ms |
27316 KB |
018.txt |
AC |
449 ms |
27204 KB |
019.txt |
AC |
458 ms |
27220 KB |
020.txt |
AC |
449 ms |
27080 KB |
021.txt |
AC |
451 ms |
27352 KB |
022.txt |
AC |
450 ms |
27276 KB |
023.txt |
AC |
449 ms |
27320 KB |
example0.txt |
AC |
1 ms |
3552 KB |
example1.txt |
AC |
1 ms |
3624 KB |