Dashboard - Codeforces Round 914 (Div. 2) - Codeforces
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
int dx[4]={-1,1,-1,1},dy[4]={-1,-1,1,1};
void solve()
{
int a,b;
cin>>a>>b;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
set<PII> st1,st2;
for(int j = 0; j < 4; j++)
{
st1.insert({x1+dx[j]*a, y1+dy[j]*b});
st2.insert({x2+dx[j]*a, y2+dy[j]*b});
st1.insert({x1+dx[j]*b, y1+dy[j]*a});
st2.insert({x2+dx[j]*b, y2+dy[j]*a});
}
int ans=0;
for(auto x:st1)
{
if(st2.find(x)!=st2.end()) ans++;
}
cout<<ans<<endl;
}
signed main()
{
int t=1;
cin>>t;
while(t--) solve();
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
const int INF = 1e9;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
template<class K> using sset = tree<K, null_type, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
inline ll ceil0(ll a, ll b) {
return a / b + ((a ^ b) > 0 && a % b);
}
void setIO() {
ios_base::sync_with_stdio(0); cin.tie(0);
}
int main(){
setIO();
int T;
cin >> T;
for(int tt = 1; tt <= T; tt++){
int n;
cin >> n;
pii arr[n + 1];
for(int i = 1; i <= n; i++) cin >> arr[i].ff, arr[i].ss = i;
sort(arr + 1, arr + n + 1);
int nxt[n + 1];
ll sum[n + 1];
int ans[n + 1];
nxt[0] = sum[0] = 0;
for(int i = 1; i <= n; i++){
if(nxt[i - 1] >= i){
nxt[i] = nxt[i - 1];
sum[i] = sum[i - 1];
} else {
sum[i] = sum[i - 1] + arr[i].ff;
nxt[i] = i;
while(nxt[i] + 1 <= n && sum[i] >= arr[nxt[i] + 1].ff){
nxt[i]++;
sum[i] += arr[nxt[i]].ff;
}
}
ans[arr[i].ss] = nxt[i];
}
for(int i = 1; i <= n; i++) cout << ans[i] - 1 << " ";
cout << endl;
}
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
if (k >= 3) {
cout << 0 << endl;
continue;
}
sort(begin(a), end(a));
int d = a[0];
for (int i = 0; i < n - 1; i++) d = min(d, a[i + 1] - a[i]);
if (k == 1) {
cout << d << endl;
continue;
}
for (int i = 0; i < n; i++) for (int j = 0; j < i; j++) {
int v = a[i] - a[j];
int p = lower_bound(begin(a), end(a), v) - begin(a);
if (p < n) d = min(d, a[p] - v);
if (p > 0) d = min(d, v - a[p - 1]);
}
cout << d << endl;
}
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
const int INF = 1e9;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
template<class K> using sset = tree<K, null_type, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
inline ll ceil0(ll a, ll b) {
return a / b + ((a ^ b) > 0 && a % b);
}
void setIO() {
ios_base::sync_with_stdio(0); cin.tie(0);
}
int main(){
setIO();
int T;
cin >> T;
for(int tt = 1; tt <= T; tt++){
int n;
cin >> n;
int a[n + 1], b[n + 1];
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
bool val[n + 1];
memset(val, false, sizeof(val));
for(int t = 0; t < 2; t++){
int prvb[n + 1];
int nxta[n + 1];
stack<pii> s;
s.push({INF, n + 1});
for(int i = n; i >= 1; i--){
while(s.top().ff <= a[i]) s.pop();
nxta[i] = s.top().ss;
s.push({a[i], i});
}
while(!s.empty()) s.pop();
s.push({0, 0});
for(int i = 1; i <= n; i++){
while(s.top().ff >= b[i]) s.pop();
prvb[i] = s.top().ss;
s.push({b[i], i});
}
int m[n + 1];
memset(m, 0, sizeof(m));
for(int i = 1; i <= n; i++){
m[a[i]] = i;
if(a[i] <= b[i] && m[b[i]]) val[i] |= prvb[i] < m[b[i]] && nxta[m[b[i]]] > i;
}
reverse(a + 1, a + n + 1);
reverse(b + 1, b + n + 1);
reverse(val + 1, val + n + 1);
}
bool ans = true;
for(int i = 1; i <= n; i++) ans &= val[i];
cout << (ans ? "YES" : "NO") << endl;
}
}