Submission #442097

#TimeUsernameProblemLanguageResultExecution timeMemory
442097keta_tsimakuridzeRestore Array (RMI19_restore)C++14
100 / 100
89 ms1224 KiB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=2e5+5,inf = 1e9+7;
int t,n,m,dist[N],upd[N];
vector<pair<pair<int,int>,int> > edges;
 main(){
	cin>>n>>m;
	for(int i=0;i<n;i++) {
		edges.push_back({{i,i+1},1});
		edges.push_back({{i+1,i},0});
	}
	
	while(m--){
		int l,r,k,val;
		cin>>l>>r>>k>>val;
		l++; r++;
		if(val==0) {
			edges.push_back({{l-1,r},r-l+1-k});
		}
		else edges.push_back({{r,l-1}, - (r-l+1-k+1)});
	}
	for(int i=1;i<=n;i++) dist[i] = inf;
	
	while(true) {
		int f=0;
		for(int i=0;i<edges.size();i++){
			int u = edges[i].f.f;
			int v = edges[i].f.s;
			if(dist[v] > dist[u] + edges[i].s) {
				f = 1;
				dist[v] = dist[u] + edges[i].s;
				upd[v]++;
				if(upd[v]==n) {
					cout<<-1;
					return 0;
				}
			}
		}
		if(!f) break;
	}
	for(int i=1;i<=n;i++) {
		cout<<dist[i]-dist[i-1]<<" ";
	}
}

Compilation message (stderr)

restore.cpp:9:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 |  main(){
      |  ^~~~
restore.cpp: In function 'int main()':
restore.cpp:29:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int i=0;i<edges.size();i++){
      |               ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...