Submission #597720

# Submission time Handle Problem Language Result Execution time Memory
597720 2022-07-16T16:41:36 Z cfalas Painting Walls (APIO20_paint) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#include "paint.h"
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

int M, N;
vi c;
map<int, vector<int>> f;
struct seg{
	unordered_set<int> val;
	seg *L, *R;
 
	unordered_set<int> merge(unordered_set<int> &a, int as, unordered_set<int> &b){
		unordered_set<int> ans;
		FOA(v,a){
			if(b.count((v + as)%M)) ans.insert(v);
		}
		return ans;
	}
 
	void build(int l=0, int r=N-1){
		if(l==r){
			FOA(v, f[c[l]]){
				val.insert(v);
			}
		}
		else{
			L = new seg;
			R = new seg;
 
			L->build(l,MID);
			R->build(MID+1,r);
 
			val = merge(L->val, MID-l+1, R->val);
		}
	}
 
	unordered_set<int> query(int rl, int rr, int l=0, int r=N-1){
		if(rl<=l && r<=rr) return val;
		else if(rr<l || r<rl) return unordered_set<int>();
		else{
			unordered_set<int> sl = L->query(rl,rr,l,MID);
			unordered_set<int> sr = R->query(rl,rr,MID+1,r);
			if(rr<=MID){
				/*
				cout<<"Return left "<<l<<" "<<r<<": ";
				FOA(v,sl) cout<<v<<" ";
				cout<<endl;*/
				return sl;
			}
			if(rl>MID){
				/*
				cout<<"Return right "<<l<<" "<<r<<": ";
				FOA(v,sr) cout<<v<<" ";
				cout<<endl;*/
				return sr;
			}
			//cout<<"merge "<<l<<" "<<r<<": ";
			unordered_set<int> qq;
			if(l<=rl) qq = merge(sl, MID-rl+1, sr);
			else qq = merge(sl, MID-l+1, sr);
			/*
			FOA(v, sl) cout<<v<<" ";
			cout<<" | ";
			FOA(v, sr) cout<<v<<" ";
			cout<<" | ";
			FOA(v, qq) cout<<v<<" ";
			cout<<endl;*/
			return qq;
		}
	}
 
	void print(int l=0, int r=N-1){
		cout<<l<<" "<<r<<": ";
		FOA(v, val) cout<<v<<" ";
		cout<<endl;
		if(l!=r){
			L->print(l, MID);
			R->print(MID+1,r);
		}
	}
};

int minimumInstructions(int n, int m, int K, std::vector<int> C, 
						vector<int> A, vector<std::vector<int>> B) {
	mm[{}] = 0;
	M = m;
	N = n;
	c = C;
	FOR(i,M){
		FOA(v, B[i]){
			f[v].push_back(i);
		}
	}
	seg s;
	s.build();
	if(s.query(0, M-1).empty()) return -1;
	int p=0;
	int cp=M;
	int ans = 1;
	while(cp<N){
		//cout<<p<<" "<<cp<<endl;
		while(s.query(cp, cp+M-1).empty()) cp--;
		if(cp<=p) return -1;
		p = cp;
		cp+=M;
		ans++;
	}
  return ans;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:104:2: error: 'mm' was not declared in this scope; did you mean 'm'?
  104 |  mm[{}] = 0;
      |  ^~
      |  m