Submission #964579

#TimeUsernameProblemLanguageResultExecution timeMemory
964579noobcodurMeteors (POI11_met)C++14
74 / 100
1179 ms35956 KiB
#include<bits/stdc++.h> using namespace std; using ld = long double; #define int long long #define pii pair<int,int> #define forn(i,j) for(int i = 0; i < j; ++i) #define forrange(i,j,k) for(int i = j; i < k; ++i) #define vi vector<int> #define vpii vector<pii> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() const int MOD = 1e9+7; const int INF = 1e17+1; const int maxN = 3e5+2; void setIO(string name){ ios_base::sync_with_stdio(0); cin.tie(0); if(!name.empty()){ freopen((name + ".in").c_str(),"r",stdin); freopen((name + ".out").c_str(),"w",stdout); } } int bit[maxN]; void update(int idx, int val){ while(idx < maxN){ bit[idx] += val; idx += idx&-idx; } } int query(int idx){ int res = 0; while(idx > 0){ res += bit[idx]; idx -= idx&-idx; } return res; } struct Query{ int t,left,right,val; }; struct Station{ int lo,mid,hi,idx; }; bool comp(Station A, Station B){ return A.mid < B.mid; } int res[maxN]; signed main(){ setIO(""); int n,m; cin >> n >> m; vector<vi> loc(n+1); vi p(n+1); forrange(i,1,m+1){ int a; cin >> a; loc[a].pb(i); } forrange(i,1,n+1){ cin >> p[i]; } int q; cin >> q; vector<Query> Q; forn(i,q){ Query T; cin >> T.left >> T.right >> T.val; T.t = 0; if(T.left > T.right){ T.t = 1; swap(T.left,T.right); } Q.pb(T); } vector<Station> S; forrange(i,1,n+1){ Station T; T.lo = 0, T.hi = q; T.mid = (T.lo + T.hi)/2; T.idx = i; S.pb(T); } while(!S.empty()){ int ptr = -1; vector<Station> curr; for(Station T : S){ if(T.lo >= T.hi){ res[T.idx] = T.lo; continue; } while(ptr < q-1 && ptr < T.mid){ ptr++; if(!Q[ptr].t){ update(Q[ptr].left,Q[ptr].val); update(Q[ptr].right+1,-Q[ptr].val); } else{ update(1,Q[ptr].val); update(Q[ptr].left+1,-Q[ptr].val); update(Q[ptr].right,Q[ptr].val); } } int ans = 0; for(int j : loc[T.idx]){ ans += query(j); } if(ans >= p[T.idx]){ T.hi = T.mid; T.mid = (T.lo + T.hi)/2; curr.pb(T); } else{ T.lo = T.mid+1; T.mid = (T.lo + T.hi)/2; curr.pb(T); } } S.clear(); sort(all(curr),comp); fill(bit,bit+m+1,0); for(Station T : curr) S.pb(T); } forrange(i,1,n+1){ if(res[i] == q){ cout << "NIE" << endl; } else cout << res[i]+1 << endl; } }

Compilation message (stderr)

met.cpp: In function 'void setIO(std::string)':
met.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen((name + ".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen((name + ".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...