# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395440 | PanTkd | Bitwise (BOI06_bitwise) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// main.cpp
//
// Created by Panagiotis Chadjicostas on
// Copyright © Panagiotis Hadjicostas. All rights reserved.
//
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define fo(i,a,b) for(int i = a; i<=b; i++)
#define f(i,b) for(int i=0;i<b;i++)
#define F first
#define S second
#define sz size
const ll MOD=ll(1e9)+7;
const ll MAXN=2*ll(1e6);
void checker(){
ll n=rand()%20+2;
vi a(n,ll());
for(ll i=0;i<n;i++){
a[i]=rand()%20+2;
}
for(ll b=0;b<(1<<n);b++){
vi on,off;
for(ll i=0;i<n;i++){
if(i&(1<<i)){
on.push_back(i);
}
else{
off.push_back(i);
}
}
}
}
///////////////////////////////////////////////////////////////////////
struct po{
ll s,e;
};
ll sc[1000];
ll l[1000];
void solve(){
ll n,p;cin>>n>>p;
for(ll i=1;i<=p;i++){
cin>>l[i];l[i]+=l[i-1];
}
po v[n+1];
for(ll i=1;i<=n;i++){
cin>>v[i].s>>v[i].e;
}
ll sol=0;
for(ll i=30;i>=0;i--){
bool ok=1;
ll put=(1<<i);
for(ll b=1;b<=p&&ok;b++){
sc[b]=0;
ok=false;
for(ll j=l[b-1]+1;j<=l[b];j++){
if(v[j].e>=put&&(v[j].s>=put||!sc[b])){
ok=true;
sc[b]=j;
}
}
}
if(ok){
sol += put;
for (ll b = 1; b <= p; b++)
v[sc[b]].s = max(v[sc[b]].s, put);
for(ll j=1;j<=n;j++){
v[j].s-=put;
v[j].e-=put;
}
}
else{
if (v[j].e>=put){
v[j].e=put-1;
}
}
}
cout<<sol<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t=1;//cin>>t;
while (t--) {
solve();
}
return 0;
}