#include <bits/stdc++.h>
#pragma optimize("03")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
const int MAX=3e5+5;
const int B=224;
const int N=1e6;
const int block=450;
const int maxB=MAX/B+10;
const ll inf=1e18;
const int mod=1e9+7;
const int mod1=1e9+9;
const int logg=15;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
set<pii> pt;
set<pii> gr;
map<pii,int> mp;
int f[MAX*10];
void init(int R, int C, int sr, int sc, int M, char *s){
pt.in({sr,sc});
for(int i=0;i<M;i++){
if(s[i]=='N')sr--;
if(s[i]=='S')sr++;
if(s[i]=='W')sc--;
if(s[i]=='E')sc++;
// cout<<sr<<" "<<sc<<"\n";
pt.in({sr,sc});
}
}
bool inthe(int ar, int br, int ac, int bc,pii x){
return ar<=x.F&&x.F<=ac&&br<=x.S&&x.S<=bc;
}
int get(int v){
if(f[v]==v)return v;
return f[v]=get(f[v]);
}
void unite(int a,int b){
a=get(a),b=get(b);
if(a==b)return;
f[a]=b;
}
int colour(int ar, int br, int ac, int bc) {
int cnt=0;
int cur=0;
gr.clear();
mp.clear();
for(pii x:pt){
if(inthe(ar,br,ac,bc,x))cnt++;
for(int i=0;i<8;i++){
int nx=x.F+dx[i],ny=x.S+dy[i];
if(!pt.count({nx,ny})&&inthe(ar,br,ac,bc,{nx,ny})){
gr.in({nx,ny});
}
}
}
if(cnt==0)return 1;
for(pii x:gr)mp[x]=++cur;
for(int i=1;i<=cur;i++)f[i]=i;
for(pii x:gr){
int num=mp[x];
for(int i=0;i<4;i++){
int nx=x.F+dx[i],ny=x.S+dy[i];
if(inthe(ar,br,ac,bc,make_pair(nx,ny))&&mp.count({nx,ny})){
int num1=mp[{nx,ny}];
unite(num,num1);
}
}
}
int ans=0;
for(int i=1;i<=cur;i++)if(get(i)==i)ans++;
return ans;
}
int main(){
int r,c,m,q;
cin>>r>>c>>m>>q;
int sr,sc;
cin>>sr>>sc;
char s[MAX];
for(int i=0;i<m;i++)cin>>s[i];
init(r,c,sr,sc,m,s);
while(q--){
int ar,br,ac,bc;
cin>>ar>>br>>ac>>bc;
cout<<colour(ar,br,ac,bc)<<"\n";
}
}
Compilation message
rainbow.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize("03")
|
rainbow.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
4 | #pragma target("avx2")
|
/usr/bin/ld: /tmp/ccaxWVLf.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccrtq8Ff.o:rainbow.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status