#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.f]!=inf&&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+2)-(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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
1368 KB |
Output is correct |
2 |
Correct |
99 ms |
1368 KB |
Output is correct |
3 |
Correct |
89 ms |
1368 KB |
Output is correct |
4 |
Correct |
87 ms |
1368 KB |
Output is correct |
5 |
Correct |
160 ms |
1876 KB |
Output is correct |
6 |
Correct |
129 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
1368 KB |
Output is correct |
2 |
Correct |
99 ms |
1368 KB |
Output is correct |
3 |
Correct |
89 ms |
1368 KB |
Output is correct |
4 |
Correct |
87 ms |
1368 KB |
Output is correct |
5 |
Correct |
160 ms |
1876 KB |
Output is correct |
6 |
Correct |
129 ms |
1368 KB |
Output is correct |
7 |
Correct |
89 ms |
1368 KB |
Output is correct |
8 |
Correct |
89 ms |
1368 KB |
Output is correct |
9 |
Correct |
90 ms |
1368 KB |
Output is correct |
10 |
Correct |
86 ms |
1364 KB |
Output is correct |
11 |
Correct |
165 ms |
1368 KB |
Output is correct |
12 |
Correct |
168 ms |
1364 KB |
Output is correct |
13 |
Correct |
88 ms |
1564 KB |
Output is correct |
14 |
Correct |
98 ms |
1364 KB |
Output is correct |
15 |
Correct |
93 ms |
1368 KB |
Output is correct |
16 |
Correct |
93 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
86 ms |
1368 KB |
Output is correct |
12 |
Correct |
99 ms |
1368 KB |
Output is correct |
13 |
Correct |
89 ms |
1368 KB |
Output is correct |
14 |
Correct |
87 ms |
1368 KB |
Output is correct |
15 |
Correct |
160 ms |
1876 KB |
Output is correct |
16 |
Correct |
129 ms |
1368 KB |
Output is correct |
17 |
Correct |
89 ms |
1368 KB |
Output is correct |
18 |
Correct |
89 ms |
1368 KB |
Output is correct |
19 |
Correct |
90 ms |
1368 KB |
Output is correct |
20 |
Correct |
86 ms |
1364 KB |
Output is correct |
21 |
Correct |
165 ms |
1368 KB |
Output is correct |
22 |
Correct |
168 ms |
1364 KB |
Output is correct |
23 |
Correct |
88 ms |
1564 KB |
Output is correct |
24 |
Correct |
98 ms |
1364 KB |
Output is correct |
25 |
Correct |
93 ms |
1368 KB |
Output is correct |
26 |
Correct |
93 ms |
1364 KB |
Output is correct |
27 |
Correct |
84 ms |
1368 KB |
Output is correct |
28 |
Correct |
93 ms |
1364 KB |
Output is correct |
29 |
Correct |
90 ms |
1364 KB |
Output is correct |
30 |
Correct |
86 ms |
1368 KB |
Output is correct |
31 |
Correct |
85 ms |
1364 KB |
Output is correct |
32 |
Correct |
93 ms |
1624 KB |
Output is correct |
33 |
Correct |
168 ms |
1364 KB |
Output is correct |
34 |
Correct |
158 ms |
1368 KB |
Output is correct |
35 |
Correct |
96 ms |
1368 KB |
Output is correct |
36 |
Correct |
87 ms |
1368 KB |
Output is correct |