QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291722 | #4817. Half Plane | Radewoosh# | WA | 107ms | 158604kb | C++20 | 5.6kb | 2023-12-27 03:40:27 | 2023-12-27 03:40:27 |
Judging History
answer
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define shandom_ruffle random_shuffle
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll mod=1000*1000*1000+7;
const int inf=1007*1007*1007;
int n, q;
struct vec
{
ll w[3];
vec()
{
for (int i=0; i<3; i++)
w[i]=0;
}
void czyt()
{
for (int i=0; i<3; i++)
scanf("%lld", &w[i]);
}
void reset()
{
for (int i=0; i<3; i++)
w[i]=0;
}
};
struct mac
{
ll w[3][3];
int pusta=0;
mac()
{
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
w[i][j]=0;
}
void czyt()
{
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
scanf("%lld", &w[i][j]);
}
void reset()
{
if (pusta)
return;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
w[i][j]=(i==j);
pusta=1;
}
};
ll pom[3][3];
void domnoz(const mac &a, mac &b)
{
if (a.pusta)
return;
if (b.pusta)
{
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
b.w[i][j]=a.w[i][j];
b.pusta=0;
return;
}
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
pom[i][j]=0;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
for (int l=0; l<3; l++)
pom[i][l]+=a.w[i][j]*b.w[j][l];
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
b.w[i][j]=pom[i][j]%mod;
}
pii tab[nax];
vec vectab[nax];
bool mniej1(int a, int b)
{
return tab[a]<tab[b];
}
bool mniej2(int a, int b)
{
pii aa=tab[a];
pii bb=tab[b];
swap(aa.first, aa.second);
swap(bb.first, bb.second);
return aa<bb;
}
int m;
pii px[nax];
pii py[nax];
mac narz[nax];
vec pod[nax];
vi dz[nax];
void push(int v)
{
for (int i : dz[v])
domnoz(narz[v], narz[i]);
narz[v].reset();
}
void dodaj(const mac &a, const vec &b, vec &c)
{
if (a.pusta)
{
for (int i=0; i<3; i++)
c.w[i]+=b.w[i];
}
else
{
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
c.w[i]+=a.w[i][j]*b.w[j];
}
for (int i=0; i<3; i++)
c.w[i]%=mod;
}
void upd(int v)
{
pod[v].reset();
for (int i : dz[v])
dodaj(narz[i], pod[i], pod[v]);
}
int nal[nax];
int build(vector<vi> wek, int parz)
{
if (wek[0].empty())
return 0;
if ((int)wek[0].size()==1)
{
int kt=wek[0][0];
m++;
pod[m]=vectab[kt];
narz[m].reset();
px[m]={tab[kt].first, tab[kt].first};
py[m]={tab[kt].second, tab[kt].second};
return m;
}
int r=wek[0].size();
const int ile=2;
for (int i=0; i<r; i++)
nal[wek[parz][i]]=(ile*i)/r;
vector<vector<vi>> podz(ile, vector<vi>(2));
for (int h=0; h<2; h++)
for (int i : wek[h])
podz[nal[i]][h].push_back(i);
m++;
int tu=m;
for (int h=0; h<ile; h++)
{
dz[tu].push_back(build(podz[h], parz^1));
if (!dz[tu].back())
dz[tu].pop_back();
}
px[tu]={inf, -inf};
py[tu]={inf, -inf};
for (int i : dz[tu])
{
px[tu].first=min(px[tu].first, px[i].first);
px[tu].second=max(px[tu].second, px[i].second);
py[tu].first=min(py[tu].first, py[i].first);
py[tu].second=max(py[tu].second, py[i].second);
}
//~ pod[tu]=daj(dz[tu][0])+daj(dz[tu][1]);
narz[tu].reset();
upd(tu);
return tu;
}
int ga, gb, gc;
mac glomac;
vec wyn;
int szuk(int v)
{
int mini=min(ga*px[v].first, ga*px[v].second)+min(gb*py[v].first, gb*py[v].second);
int maxi=max(ga*px[v].first, ga*px[v].second)+max(gb*py[v].first, gb*py[v].second);
if (mini>=gc)
{
return 0;
}
if (maxi<gc)
{
dodaj(narz[v], pod[v], wyn);
domnoz(glomac, narz[v]);
return 1;
}
assert(!dz[v].empty());
push(v);
int ret=0;
for (int i : dz[v])
ret|=szuk(i);
if (ret)
upd(v);
return ret;
}
int main()
{
scanf("%d", &n);
for (int i=1; i<=n; i++)
{
int x, y;
vec w;
scanf("%d%d", &x, &y);
tab[i]={x, y};
vectab[i].czyt();
}
vi k1, k2;
for (int i=1; i<=n; i++)
k1.push_back(i);
k2=k1;
sort(k1.begin(), k1.end(), mniej1);
sort(k2.begin(), k2.end(), mniej2);
int korz=build({k1, k2}, 0);
scanf("%d", &q);
while(q--)
{
scanf("%d%d%d", &ga, &gb, &gc);
glomac.czyt();
wyn=vec();
szuk(korz);
for (int i=0; i<3; i++)
printf("%lld ", wyn.w[i]);
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 153676kb
input:
5 1 1 2 3 4 12 12 4 6 1 1 12 5 1 2 12 1 1 5 5 6 6 2 0 3 3 1 1 4 1 1 2 3 4 5 2 3 4 1 1 400 1 3 4 2 1 2 3 4 5 -1 -1 -10 3 2 1 4 6 5 4 3 2
output:
2 3 4 25 50 40 92 58 139
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 12ms
memory: 154664kb
input:
8 -509 1134 869419079 764178960 818736647 -2836 296 965929020 482991943 829626659 1594 -1045 289612318 572608619 474362463 -2946 -165 85255903 285022572 770151631 -74 -131 732523347 283776652 211209006 -627 -604 539714672 763810142 817996815 -1187 -1219 734874008 764773559 261445054 -18 226 31476550...
output:
242481509 621755738 615459217 984440526 242571329 417013116 122667367 215125161 518083968 594780462 21825000 214574293
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 107ms
memory: 158604kb
input:
30000 676 -1234 836467424 502287177 140023561 -2003 -54 939673593 585085650 422504901 14185 -49892 469301115 424738168 942143157 -6019 4933 573698653 956514739 385606216 -1097 -1767 918532462 279450765 873950517 -2732 5210 428418604 607751438 2805137 -2791 1240 250817926 463999452 951276698 -3460 -5...
output:
538200103 176562537 786040129 282120049 585253989 126746038 43932475 161032948 466157300 771691585 790095257 189310296 347979776 523953756 525028793 397850013 343639408 499844276 951865095 627308909 107607740 573609381 579891780 593086586 866634542 87666122 384541340 146541981 808374820 627...
result:
wrong answer 3rd lines differ - expected: '442585365 946639191 152848161', found: '43932475 161032948 466157300 '