This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e6;
int mn[N],mx[N];
uint8_t color[N];
ll st[2 * N];
void build(int l, int r, int node){
if(l == r){
st[node] = 1ll<<color[l];
return;
}
int mid = (l + r) >> 1;
build(l, mid, node + 1);
build(mid + 1, r, node + 2 * (mid - l + 1));
st[node] = st[node + 1] | st[node + 2 * (mid - l + 1)];
}
ll query(int ql, int qr, int l, int r, int node){
if(l > qr || r < ql)
return 0;
if(ql <= l && r <= qr){
return st[node];
}
int mid = (l + r) >> 1;
return query(ql, qr, l, mid, node + 1) | query(ql, qr, mid + 1, r, node + 2 * (mid - l + 1));
}
int main() {
int k;
cin>>k;
pair<int,uint8_t> arr[N];
int cur=0;
int tot=0;
for(int i = 0; i < k; i++){
int n;
cin>>n;
tot+=n;
for(int j = 0; j < n; j++){
int w;
cin>>w;
arr[cur].first=w,arr[cur].second=i;
++cur;
}
}
sort(arr, arr+tot);
cur=0;
int curmn=arr[0].first,curmx=arr[0].first,curc=arr[0].second;
for(int i = 1; i < tot; i++){
if(arr[i].second != arr[i - 1].second){
mn[cur]=curmn;
mx[cur]=curmx;
color[cur]=curc;
curmn=curmx=arr[i].first,curc=arr[i].second;
++cur;
}else{
curmx=arr[i].first;
}
}
mn[cur]=curmn,mx[cur]=curmx,color[cur]=curc;
++cur;
int n = cur;
build(0, n - 1, 0);
int r = 2;
for(int i = 0; i + 2 < n; i++){
if(__builtin_popcountll(query(i, n - 1, 0, n - 1, 0)) < 3)break;
while(__builtin_popcountll(query(i, r, 0, n - 1, 0)) < 3){
r++;
}
//i,i+1,r
if(mx[i]+mx[i+1]>mn[r]){
return cout<<color[i]+1<<' '<<mx[i]<<' '<<color[i+1]+1<<' '<<mx[i+1]<<' '<<color[r]+1<<' '<<mn[r], 0;
}
}
cout<<"NIE";
return 0;
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |