QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#101799 | #4236. Triangular Logs | joesmitty | WA | 269ms | 34772kb | C++20 | 4.5kb | 2023-05-01 09:45:10 | 2023-05-01 09:45:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
#define endl '\n';
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
template <typename T>
void pr(vector<T> &v) {
FOR(i, 0, sz(v)) cout << v[i] << " ";
cout << endl;
}
template <typename T>
void pr(vector<vector<T> > &v) {
FOR(i, 0, sz(v)) { pr(v[i]); }
}
template <typename T>
void re(T &x) {
cin >> x;
}
template <typename T>
void re(vector<T> &a) {
FOR(i, 0, sz(a)) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &... rest) {
re(first);
re(rest...);
}
template <typename T>
void pr(T x) {
cout << x << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &... rest) {
cout << first << " ";
pr(rest...);
cout << endl;
}
void ps() { cout << endl; }
template<class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
cout << t; if (sizeof...(ts)) cout << " "; ps(ts...);
}
const ll MOD = 998244353;
#define inf 1e18;
#define INF INT_MAX
long double PI = 4*atan(1);
long double eps = 1e-12;
int n,q;
vi xvals;
vector<piii> ts;
vector<pii> st[400100] = {};
int yl, yh;
vi res;
void insert(int p, int l, int r, int x, int y, int h) {
if(l == r) {
st[p].pb({y, h});
//cout << p << " " << st[p].size() << endl;
return;
}
int m = (l + r)/2;
st[p].pb({y, h});
if(x <= m) {
insert(2*p, l, m, x, y, h);
} else {
insert(2*p+1, m+1, r, x, y, h);
}
}
void query(int p, int l, int r, int ql, int qr) {
if(qr < l || r < ql) return;
if(ql <= l && r <= qr) {
// cout << "HI" << " " << l << " " << r << endl;
int lo = lower_bound(st[p].begin(), st[p].end(), (pii) {yl, -1}) - st[p].begin();
for(int i = lo; i < st[p].size(); i++) {
if(st[p][i].ff > yh) return;
res.pb(st[p][i].ss);
if(res.size() >= 60) return;
}
return;
}
int m = (l + r)/2;
query(2*p, l, m, ql, qr);
if(res.size() >= 60) return;
query(2*p+1, m+1, r, ql, qr);
return;
}
int main() {
//auto start = chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);cin.tie(0);
// ofstream cout("disrupt.out");
// ifstream cin("disrupt.in");
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n >> q;
ts.resize(n);
FOR(i,0,n) {
int x,y,h; cin >> x >> y >> h;
xvals.pb(x);
ts[i] = {{x,y}, h};
}
sort(all(xvals));
xvals.resize(unique(all(xvals)) - xvals.begin());
FOR(i,0,n) {
int xc = lower_bound(all(xvals), ts[i].ff.ff) - xvals.begin();
// cout << xc << endl;
insert(1, 0, 100000, xc, ts[i].ff.ss, ts[i].ss);
}
FOR(i,0,400100) sort(all(st[i]));
// for(auto v : st[1]) {
// cout << v.ff << ", " << v.ss << endl;
// }
FOR(i,0,q) {
res.clear();
int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
yl = y1; yh = y2;
int xl = lower_bound(all(xvals), x1) - xvals.begin();
int xr = lower_bound(all(xvals), x2) - xvals.begin();
// cout << xl << " " << xr << endl;
query(1, 0, 100000, xl, xr);
if(res.size() >= 60) {
cout << 1 << endl;
continue;
}
if(res.size() < 3) {
cout << 0 << endl;
continue;
}
sort(all(res));
// pr(res);
bool good = false;
FOR(i,0,res.size() - 2) {
if(res[i] + res[i+1] > res[i+2]) good =true;
}
cout << good << endl;
// cout << "----" << endl;
}
// auto stop = chrono::high_resolution_clock::now();
// auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
// cout << duration.count() << endl;
//cin.close();
//cout.close();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12780kb
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: 3ms
memory: 12936kb
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: 6ms
memory: 12872kb
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: 0
Accepted
time: 222ms
memory: 31672kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #5:
score: 0
Accepted
time: 229ms
memory: 31520kb
input:
100000 100000 299999990 299999990 40343876 299999990 299999991 75128878 299999990 299999992 54630219 299999990 299999993 2733654 299999990 299999994 46236519 299999990 299999995 98430004 299999990 299999996 48355189 299999990 299999997 85287882 299999990 299999998 83938086 299999990 299999999 739070...
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:
ok 100000 lines
Test #6:
score: 0
Accepted
time: 269ms
memory: 34424kb
input:
100000 100000 586649484 999402721 770254678 406977522 613559 332964690 987164 445493717 518079399 249557488 999424331 597100212 143514230 999205612 56986976 933588533 509797 769263555 696911 930171165 201130067 833170 541105172 912457971 145501 423684829 612968794 999276416 167526939 136454621 70428...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #7:
score: -100
Wrong Answer
time: 268ms
memory: 34772kb
input:
100000 100000 341071 873501571 1101 59980263 526804 9 297715277 999186682 197674 709891830 999005915 346 999712634 250379232 3158 999959502 879534904 11273 253455643 999864444 49222 427866822 999577133 210191465 729566332 999548170 14 657471525 144302 846059 319542083 999756032 6275 219750473 765955...
output:
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 ...
result:
wrong answer 26724th lines differ - expected: '0', found: '1'