#include<bits/stdc++.h> #define ll long long #define ld long double #define int long long #define N 50 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define all(x) x.begin(),x.end() #define pii pair<int,int> #define x first #define y second usingnamespace std; int n; bool a[N],b[N],f = 1;
#include<bits/stdc++.h> #define ll long long #define ld long double #define int long long #define N 100 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define all(x) x.begin(),x.end() #define pii pair<int,int> #define x first #define y second usingnamespace std; int n,m,k; bool maze[N][N],bomb[N][N];
structnode{ int x,y,s,t; bool alive; }mp[505];
signedmain(){ Orz; memset(maze,0,sizeof(maze)); cin>>n>>m>>k; rep(i,0,k-1){ cin>>mp[i].x>>mp[i].y; cin>>mp[i].s>>mp[i].t; mp[i].alive = 1; } int now_alive = k; while(now_alive){ memset(bomb,0,sizeof(bomb)); for(int p=0;p<k;p++){ if(mp[p].alive == 0)continue; int i = mp[p].x,j = mp[p].y; maze[i][j] = 1; } for(int p=0;p<k;p++){ if(mp[p].alive == 0)continue; int i = mp[p].x,j = mp[p].y; int nx = i + mp[p].s; int ny = j + mp[p].t; if(nx >= n || nx < 0 || ny >= m ||ny < 0){ now_alive--; mp[p].alive = 0; } elseif(maze[nx][ny]){ now_alive--; mp[p].alive = 0; bomb[nx][ny] = 1; } else{ mp[p].x = nx; mp[p].y = ny; } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(bomb[i][j] == 1) maze[i][j] = 0; } } } int ans = 0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(maze[i][j])ans++; } } cout<<ans<<endl; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define int long long #define N 300005 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define all(x) x.begin(),x.end() #define pii pair<int,int> #define x first #define y second usingnamespace std; int n,arr[N],pref[N]; pii sorted[N];
while(r>l){ while(sorted[ind].y > r || sorted[ind].y < l)ind++; int left = pref[sorted[ind].y-1]-pref[l-1]; int right = pref[r]-pref[sorted[ind].y]; if(left > right){ r = sorted[ind].y-1; } else{ l = sorted[ind].y+1; } } cout<<arr[l]<<endl; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define int long long #define N 300005 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define all(x) x.begin(),x.end() #define pii pair<int,int> #define x first #define y second usingnamespace std; int n,arr[N],pref[N]; pii seg[4*N];
//詢問區間最小值,回傳pair pii query(int cur,int l,int r,int ql,int qr){ if(r <= l || ql >= r || qr <= l)return {INT_MAX,INT_MAX}; if(ql <= l && qr >= r)return seg[cur]; int mid = (l+r)/2; pii lft = query(2*cur,l,mid,ql,qr); pii rgt = query(2*cur+1,mid,r,ql,qr); if(lft.x < rgt.x)return lft; return rgt; }
signedmain(){ Orz; cin>>n; rep(i,1,n){ cin>>arr[i]; pref[i] = pref[i-1]+arr[i]; } build(1,1,n+1); int l = 1,r = n+1; while(r - l > 1){ int ind = query(1,1,n+1,l,r).y; int left = pref[ind-1] - pref[l-1]; int right = pref[r-1] - pref[ind]; if(left > right)r = ind; else l = ind + 1; } cout<<arr[l]<<"\n"; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define int long long #define N 1000005 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define all(x) x.begin(),x.end() #define pii pair<int,int> #define x first #define y second usingnamespace std; int n,k,dp[2][N],lft[N],arr[N]; int mp[N];