QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109052 | #4236. Triangular Logs | swapnilg | WA | 1416ms | 416472kb | C++14 | 8.9kb | 2023-05-27 11:11:19 | 2023-05-27 11:11:21 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define pb push_back
int x[100000];
int y[100000];
int h[100000];
vector<int> xcoords;
vector<int> ycoords;
vector<int> segtree_ycoords[400000];
vector<int> segtree[400000];
vector<vector<pair<int, int> > > firsth[400000];
vector<int> numpoints[400000];
int n, q;
ll numops=0;
void add_single_ycoord(int rt, int l, int r, int pos, int ycoord, int height)
{
if (l>pos) return;
if (r<pos) return;
segtree_ycoords[rt].pb(ycoord);
firsth[rt].resize(2);
firsth[rt][1].pb(pair<int, int> (ycoord, height));
numpoints[rt].resize(2, 0);
numpoints[rt][1]++;
if (l==r) return;
add_single_ycoord(2*rt, l, (l+r)/2, pos, ycoord, height);
add_single_ycoord(2*rt+1, (l+r)/2+1, r, pos, ycoord, height);
}
void build_ysegtree_h(int rt, int yrt, int yl, int yr)
{
numops++;
//cout << rt << " " << yrt << " " << yl << " " << yr << endl;
if (yl==yr) return;
//cout << "build_ysegtree_h here " << rt << " " << yrt << " " << yl << " " << yr << endl;
int mid=(yl+yr)/2;
int midpos=segtree_ycoords[rt][mid];
for (int i=0; i<firsth[rt][yrt].size(); i++)
{
if (firsth[rt][yrt][i].first<=segtree_ycoords[rt][mid])
{
numpoints[rt][2*yrt]++;
//if (firsth[rt][2*yrt].size()<44)
firsth[rt][2*yrt].pb(firsth[rt][yrt][i]);
}
else{
numpoints[rt][2*yrt+1]++;
//if (firsth[rt][2*yrt+1].size()<44)
firsth[rt][2*yrt+1].pb(firsth[rt][yrt][i]);
}
}
build_ysegtree_h(rt, 2*yrt, yl, (yl+yr)/2);
build_ysegtree_h(rt, 2*yrt+1, (yl+yr)/2+1, yr);
}
void build_ycoords(int l, int r, int rt)
{
numops++;
//cout << l << " " << r << " " << rt << endl;
//cout << l << r << rt << endl;
/*for (int i=0; i<n; i++)
{
int pos=int(lower_bound(xcoords.begin(), xcoords.end(), x[i])-xcoords.begin());
if (pos>=l && pos<=r)
{
segtree_ycoords[rt].pb(y[i]);
}
}*/
//cout << segtree_ycoords[rt].size();
sort(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end());
segtree_ycoords[rt].resize(unique(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end())-segtree_ycoords[rt].begin());
segtree[rt].resize(4*segtree_ycoords[rt].size());
firsth[rt].resize(4*segtree_ycoords[rt].size());
numpoints[rt].resize(4*segtree_ycoords[rt].size(), 0);
//cout << l << " " << r << " " << rt << endl;
//for (int i=0; i<segtree_ycoords[rt].size(); i++)
//cout << segtree_ycoords[rt][i] << " ";
//cout << endl;
/*for (int i=0; i<n; i++)
{
int pos=int(lower_bound(xcoords.begin(), xcoords.end(), x[i])-xcoords.begin());
if (pos>=l && pos<=r)
{
//if (firsth[rt][1].size()<44)
//{
firsth[rt][1].pb(pair<int, int> (y[i], h[i]));
//}
numpoints[rt][1]++;
}
}*/
//cout << firsth[rt][1].size();
//cout << numpoints[rt][1] << endl;
//cout << "made it here" << endl;
//cout << rt << " " << segtree_ycoords[rt].size()-1 << endl;
build_ysegtree_h(rt, 1, 0, segtree_ycoords[rt].size()-1);
if (l==r) return;
build_ycoords(l, (l+r)/2, 2*rt);
build_ycoords((l+r)/2+1, r, 2*rt+1);
}
int ysum(int rt, int yrt, int l, int r, int yl, int yr)
{
if (r<yl || l>yr)
return 0;
if (yl<=l && yr>=r)
return numpoints[rt][yrt];
return ysum(rt, 2*yrt, l, (l+r)/2, yl, yr)+ysum(rt, 2*yrt+1, (l+r)/2+1, r, yl, yr);
}
int querysum(int rt, int l, int r, int xl, int xr, int yl_coord, int yr_coord)
{
if (xl>r || xr<l) return 0;
if (xl<=l && xr>=r)
{
int yl=int(lower_bound(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end(), yl_coord)-segtree_ycoords[rt].begin());
int yr=int(upper_bound(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end(), yr_coord)-segtree_ycoords[rt].begin())-1;
if (yr<yl) return 0;
return ysum(rt, 1, 0, segtree_ycoords[rt].size()-1, yl, yr);
}
return querysum(2*rt, l, (l+r)/2, xl, xr, yl_coord, yr_coord) + querysum(2*rt, (l+r)/2+1, r, xl, xr, yl_coord, yr_coord);
}
vector<int> yvec(int rt, int yrt, int l, int r, int yl, int yr)
{
if (r<yl || l>yr)
return vector<int>();
if (yl<=l && yr>=r)
{
vector<int> temp;
for (int a=0; a<firsth[rt][yrt].size(); a++)
{
temp.pb(firsth[rt][yrt][a].second);
}
return temp;
}
vector<int> a=yvec(rt, 2*yrt, l, (l+r)/2, yl, yr);
vector<int> b=yvec(rt, 2*yrt+1, (l+r)/2+1, r, yl, yr);
for (int i=0; i<b.size(); i++)
a.pb(b[i]);
return a;
}
vector<int> queryvec(int rt, int l, int r, int xl, int xr, int yl_coord, int yr_coord)
{
if (xl>r || xr<l) return vector<int>();
if (xl<=l && xr>=r)
{
int yl=int(lower_bound(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end(), yl_coord)-segtree_ycoords[rt].begin());
int yr=int(upper_bound(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end(), yr_coord)-segtree_ycoords[rt].begin())-1;
if (yr<yl)
return vector<int>();
return yvec(rt, 1, 0, segtree_ycoords[rt].size()-1, yl, yr);
}
vector<int> a=queryvec(2*rt, l, (l+r)/2, xl, xr, yl_coord, yr_coord);
vector<int> b=queryvec(2*rt, (l+r)/2+1, r, xl, xr, yl_coord, yr_coord);
for (int i=0; i<b.size(); i++)
a.pb(b[i]);
return a;
}
int main()
{
cin >> n >> q;
for (int i=0; i<n; i++)
{
//x[i]=rand()%1000000;
//y[i]=rand()%1000000;
//h[i]=rand()%1000000;
cin >> x[i] >> y[i] >> h[i];
//cout << x[i] << " " << y[i] << " " << h[i] << endl;
xcoords.pb(x[i]);
ycoords.pb(y[i]);
}
sort(xcoords.begin(), xcoords.end());
xcoords.resize(unique(xcoords.begin(), xcoords.end())-xcoords.begin());
sort(ycoords.begin(), ycoords.end());
ycoords.resize(unique(ycoords.begin(), ycoords.end())-ycoords.begin());
for (int i=0; i<n; i++)
{
int pos=int(lower_bound(xcoords.begin(), xcoords.end(), x[i])-xcoords.begin());
add_single_ycoord(1, 0, xcoords.size()-1, pos, y[i], h[i]);
}
build_ycoords(0, xcoords.size()-1, 1);
/*for (int i=1; i<=5; i++)
{
for (int j=0; j<numpoints[i].size(); j++)
{
cout << i << " " << j << " " << numpoints[i][j] << " " << firsth[i][j].size() << endl;
}
}*/
//cout << "this is the number of operations: " << numops << endl;
//for (int i=0; i<xcoords.size(); i++)
//cout << xcoords[i] << " ";
//cout << endl;
for (int tctr=0; tctr<q; tctr++)
{
int x0, y0, x1, y1;
//x0=rand()%1000000;
//y0=rand()%1000000;
//x1=x0+rand()%1000000;
//y1=y0+rand()%1000000;
cin >> x0 >> y0 >> x1 >> y1;
//cout << x0 << " " << y0 << " " << x1 << " " << y1 << endl;
//cout << x0 << " " << x1 << endl;
if (x1<xcoords[0] || x0>xcoords.back() || y1<ycoords[0] || y0>ycoords.back())
{
cout << 0 << endl;
continue;
}
int xl=int(lower_bound(xcoords.begin(), xcoords.end(), x0)-xcoords.begin());
int xr=int(upper_bound(xcoords.begin(), xcoords.end(), x1)-xcoords.begin())-1;
if (xl>xr)
{
cout << 0 << endl;
continue;
}
//cout << xl << " " << xr << endl;
int howmanypoints=querysum(1, 0, xcoords.size()-1, xl, xr, y0, y1);
//cout << "num points: " << howmanypoints << endl;
if (howmanypoints>50)
{
cout << 1 << endl;
}
else
{
vector<int> temp=queryvec(1, 0, xcoords.size()-1, xl, xr, y0, y1);
//cout << temp.size() << " this is the num of poitns" << endl;
sort(temp.begin(), temp.end());
//cout << temp.size() << " this is the num of poitns" << endl;
bool flag=false;
//for (int i=0; i<temp.size(); i++)
//cout << temp[i] << " ";
//cout << endl;
if (temp.size()<3)
{
cout << 0 << endl;
continue;
}
for (int i=1; i<temp.size()-1; i++)
{
//cout << i << " " << temp.size() << endl;
//if (i>=temp.size())
//cout << "what is happening" << endl;
if (temp[i]+temp[i-1]>temp[i+1])
{
flag=true;
break;
}
}
//cout << temp.size() << " this is the num of poitns" << endl;
if (flag)
cout << 1 << endl;
else
cout << 0 << endl;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 41136kb
input:
9 5 1 3 3 2 3 1 3 3 4 1 2 1 2 2 5 3 2 9 1 1 2 2 1 6 3 1 5 1 1 1 2 1 1 2 2 1 1 1 3 1 2 3 2 1 1 3 3
output:
0 1 0 0 1
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 6ms
memory: 42064kb
input:
481 1 8 6788 8975 24 6552 2668 26 7948 4730 40 531 9805 110 1914 1916 164 7073 3371 165 6293 7756 170 9946 2003 179 9654 1700 215 6447 2229 221 3149 3030 242 1999 6843 242 5764 3163 249 3716 8634 250 6801 9317 260 2741 4273 282 5436 4836 284 3951 6483 288 4812 76 375 9004 5492 380 5627 5929 391 6385...
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 13ms
memory: 41744kb
input:
378 1 62730 50925 80731 92666 77280 61521 29236 67032 7889 35986 96802 8763 13313 49918 83582 51842 66775 47834 2286 12925 41106 39790 6698 15243 65145 56379 68496 35570 809 525 39834 16723 48002 77230 16273 16032 52615 7621 77300 92267 82517 39917 13170 89084 77751 45638 23868 49631 7758 71381 5191...
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Wrong Answer
time: 1416ms
memory: 416472kb
input:
100000 100000 299999993 206450345 26023928 334281171 300000008 18107965 318653732 299999990 82338399 299999997 393028366 37212808 299999992 208114125 82126189 300000002 303613195 34463905 270033576 299999993 49200970 300000003 249755524 5829381 300000003 367329175 12867359 300000009 337452692 131045...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '0', found: '1'