#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,int>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
const int mod=998244353,mxn=5e3+5,lg=30,inf=1e18,minf=-1e18,Mxn=100000;
vector<ppii>e;
int dist[mxn+10];
int32_t main(){
fastio
int n,m;cin>>n>>m;
for(int i=1;i<=n;i++){
e.pb({{i,i-1},0});
e.pb({{i-1,i},1});
}
for(int i=0;i<m;i++){
int l,r,k,val;cin>>l>>r>>k>>val;
l++,r++;
if(val)e.pb({{r,l-1},l+k-r+2});
else e.pb({{l-1,r},r-l+1-k});
}
fill(dist,dist+n+10,inf);
dist[0]=0;
bool can=true;
for(int j=0;j<=n;j++){
for(auto i:e)if(dist[i.f.s]>dist[i.f.f]+i.s){
dist[i.f.s]=dist[i.f.f]+i.s;
if(j==n)can=false;
}
}
if(can)for(int i=1;i<=n;i++)cout<<dist[i]-dist[i-1]<<" ";
else cout<<-1;
return 0;
/*
pi<=pi+1
pi-pi+1<=0
pi+1-pi<=1
r=r+1,l=l+1
(r-l+1)-(psr-psl-1)<=k+1
r-l-k<=psr-psl-1
psl-1-psr<=l+k-r
psr->psl-1 w=l+k-r+2
(r-l+1)-(psr-psl-1)>=k
psr-psl-1<=r-l+1-k
psl-1->psr w=r-l+1-k
*/
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
1368 KB |
Output is correct |
2 |
Correct |
99 ms |
1364 KB |
Output is correct |
3 |
Correct |
89 ms |
1368 KB |
Output is correct |
4 |
Incorrect |
85 ms |
1364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
1368 KB |
Output is correct |
2 |
Correct |
99 ms |
1364 KB |
Output is correct |
3 |
Correct |
89 ms |
1368 KB |
Output is correct |
4 |
Incorrect |
85 ms |
1364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |