Submission #568861

#TimeUsernameProblemLanguageResultExecution timeMemory
568861errorgornReconstruction Project (JOI22_reconstruction)C++17
7 / 100
2637 ms18776 KiB
#include <bits/stdc++.h> using namespace std; #define ii pair<int,int> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n,m,q; vector<int> w[100005]; int idx[100005]; signed main(){ cin.tie(0); cout.tie(0); cin.sync_with_stdio(false); cin>>n>>m; int a,b,c; rep(x,0,m){ cin>>a>>b>>c; w[a].pub(c); } rep(x,1,n) sort(all(w[x])); cin>>q; while (q--){ int val; cin>>val; long long ans=0; rep(x,1,n){ while (idx[x]+1<sz(w[x]) && abs(w[x][idx[x]+1]-val)<abs(w[x][idx[x]]-val)){ idx[x]++; } ans+=abs(w[x][idx[x]]-val); } cout<<ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...