이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "rainbow.h"
int r,c;
int lx,rx,ly,ry;
vi tree[4][1 << 19];
int sorted[4][1 << 19];
int update(int s,int e,int ay,int ax,int i,int t) {
if ((s > ay) || (e < ay)) return 0;
else if (s == e) {
tree[t][i].pb(ax);
return 0;
}
int mid = (s+e) / 2;
update(s,mid,ay,ax,2*i+1,t);
update(mid+1,e,ay,ax,2*i+2,t);
tree[t][i].pb(ax);
return 0;
}
int query(int s,int e,int qys,int qye,int qxs,int qxe,int i,int t) {
if ((qys > qye) || (qxs > qxe)) return 0;
else if ((s > qye) || (e < qys)) return 0;
else if ((s >= qys) && (e <= qye)) {
if (!sorted[t][i]) sort(tree[t][i].begin(),tree[t][i].end()),sorted[t][i] = 1;
return upper_bound(tree[t][i].begin(),tree[t][i].end(),qxe) \
- lower_bound(tree[t][i].begin(),tree[t][i].end(),qxs);
}
int mid = (s+e) / 2;
return query(s,mid,qys,qye,qxs,qxe,2*i+1,t)+query(mid+1,e,qys,qye,qxs,qxe,2*i+2,t);
}
vpii p1,p2,p3,p4;
void init(int R,int C,int sr,int sc,int M,char *S) {
int i;
r = R,c = C;
sr--,sc--;
lx = rx = sc,ly = ry = sr;
p1.pb(mp(sr+1,sc+1));
p2.pb(mp(sr+1,sc+1)),p2.pb(mp(sr,sc+1));
p3.pb(mp(sr+1,sc+1)),p3.pb(mp(sr+1,sc));
p4.pb(mp(sr+1,sc+1)),p4.pb(mp(sr,sc+1)),p4.pb(mp(sr+1,sc)),p4.pb(mp(sr,sc));
for (i = 0; i < M; i++) {
if (S[i] == 'N') sr--;
else if (S[i] == 'S') sr++;
else if (S[i] == 'W') sc--;
else sc++;
lx = min(lx,sc),rx = max(rx,sc);
ly = min(lx,sr),ry = max(ry,sr);
p1.pb(mp(sr+1,sc+1));
p2.pb(mp(sr+1,sc+1)),p2.pb(mp(sr,sc+1));
p3.pb(mp(sr+1,sc+1)),p3.pb(mp(sr+1,sc));
p4.pb(mp(sr+1,sc+1)),p4.pb(mp(sr,sc+1)),p4.pb(mp(sr+1,sc)),p4.pb(mp(sr,sc));
}
sort(p1.begin(),p1.end());
p1.resize(unique(p1.begin(),p1.end())-p1.begin());
sort(p2.begin(),p2.end());
p2.resize(unique(p2.begin(),p2.end())-p2.begin());
sort(p3.begin(),p3.end());
p3.resize(unique(p3.begin(),p3.end())-p3.begin());
sort(p4.begin(),p4.end());
p4.resize(unique(p4.begin(),p4.end())-p4.begin());
for (i = 0; i < p1.size(); i++) update(0,r,p1[i].first,p1[i].second,0,0);
for (i = 0; i < p2.size(); i++) update(0,r,p2[i].first,p2[i].second,0,1);
for (i = 0; i < p3.size(); i++) update(0,r,p3[i].first,p3[i].second,0,2);
for (i = 0; i < p4.size(); i++) update(0,r,p4[i].first,p4[i].second,0,3);
}
int colour(int ar,int ac,int br,int bc) {
ar--,ac--,br--,bc--;
LLI ans = 0;
ans += (LLI) (br-ar+1)*(bc-ac+1)-query(0,r,ar+1,br+1,ac+1,bc+1,0,0);
ans -= (LLI) (br-ar)*(bc-ac+1)-query(0,r,ar+1,br,ac+1,bc+1,0,1);
ans -= (LLI) (br-ar+1)*(bc-ac)-query(0,r,ar+1,br+1,ac+1,bc,0,2);
ans += (LLI) (br-ar)*(bc-ac)-query(0,r,ar+1,br,ac+1,bc,0,3);
if ((ar < ly) && (br > ry) && (ac < lx) && (bc > rx)) ans++;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:118:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < p1.size(); i++) update(0,r,p1[i].first,p1[i].second,0,0);
~~^~~~~~~~~~~
rainbow.cpp:119:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < p2.size(); i++) update(0,r,p2[i].first,p2[i].second,0,1);
~~^~~~~~~~~~~
rainbow.cpp:120:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < p3.size(); i++) update(0,r,p3[i].first,p3[i].second,0,2);
~~^~~~~~~~~~~
rainbow.cpp:121:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < p4.size(); i++) update(0,r,p4[i].first,p4[i].second,0,3);
~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |