結果
問題 | No.1216 灯籠流し/Lanterns |
ユーザー | kaage |
提出日時 | 2020-08-01 13:44:46 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 7,045 bytes |
コンパイル時間 | 2,050 ms |
コンパイル使用メモリ | 152,856 KB |
実行使用メモリ | 418,812 KB |
最終ジャッジ日時 | 2024-11-14 17:58:20 |
合計ジャッジ時間 | 78,883 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
32,660 KB |
testcase_01 | AC | 12 ms
34,704 KB |
testcase_02 | AC | 11 ms
34,576 KB |
testcase_03 | AC | 11 ms
34,708 KB |
testcase_04 | AC | 58 ms
40,652 KB |
testcase_05 | AC | 4,436 ms
59,236 KB |
testcase_06 | AC | 159 ms
38,468 KB |
testcase_07 | AC | 3,735 ms
48,816 KB |
testcase_08 | AC | 2,686 ms
50,912 KB |
testcase_09 | AC | 1,148 ms
41,784 KB |
testcase_10 | AC | 1,170 ms
43,324 KB |
testcase_11 | AC | 597 ms
36,652 KB |
testcase_12 | AC | 100 ms
37,180 KB |
testcase_13 | AC | 941 ms
39,816 KB |
testcase_14 | AC | 243 ms
39,752 KB |
testcase_15 | AC | 336 ms
40,568 KB |
testcase_16 | AC | 550 ms
46,580 KB |
testcase_17 | AC | 328 ms
40,096 KB |
testcase_18 | AC | 346 ms
41,608 KB |
testcase_19 | AC | 1,236 ms
47,540 KB |
testcase_20 | AC | 734 ms
42,656 KB |
testcase_21 | AC | 502 ms
41,888 KB |
testcase_22 | AC | 564 ms
45,628 KB |
testcase_23 | AC | 126 ms
44,044 KB |
testcase_24 | AC | 72 ms
35,464 KB |
testcase_25 | AC | 52 ms
37,356 KB |
testcase_26 | AC | 291 ms
37,880 KB |
testcase_27 | AC | 360 ms
37,940 KB |
testcase_28 | AC | 322 ms
38,184 KB |
testcase_29 | AC | 676 ms
41,800 KB |
testcase_30 | AC | 671 ms
39,040 KB |
testcase_31 | AC | 526 ms
41,076 KB |
testcase_32 | AC | 915 ms
41,240 KB |
testcase_33 | AC | 231 ms
39,796 KB |
testcase_34 | TLE | - |
testcase_35 | AC | 4,162 ms
418,812 KB |
testcase_36 | AC | 3,486 ms
53,536 KB |
testcase_37 | AC | 1,979 ms
45,108 KB |
testcase_38 | AC | 813 ms
46,056 KB |
testcase_39 | AC | 3,641 ms
45,172 KB |
testcase_40 | AC | 4,150 ms
48,420 KB |
testcase_41 | AC | 4,105 ms
45,832 KB |
testcase_42 | AC | 4,063 ms
52,200 KB |
testcase_43 | AC | 4,049 ms
52,196 KB |
testcase_44 | AC | 4,035 ms
51,976 KB |
testcase_45 | AC | 2,065 ms
49,524 KB |
testcase_46 | AC | 2,076 ms
49,396 KB |
testcase_47 | AC | 2,058 ms
47,696 KB |
testcase_48 | AC | 2,105 ms
49,524 KB |
testcase_49 | AC | 2,092 ms
49,396 KB |
ソースコード
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp" #define _CRT_SECURE_NO_WARNINGS #pragma target("avx") #pragma optimize("O3") #pragma optimize("unroll-loops") #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <string.h> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define rep(i,n) for(int i=0;i<(lint)(n);i++) #define REP(i,n) for(int i=1;i<=(lint)(n);i++) #define all(V) V.begin(),V.end() typedef long long lint; typedef unsigned long long ulint; typedef std::pair<int, int> P; typedef std::pair<lint, lint> LP; constexpr int INF = INT_MAX/2; constexpr lint LINF = LLONG_MAX/2; constexpr double eps = DBL_EPSILON; constexpr double PI=3.141592653589793238462643383279; template<class T> class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {}; template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } inline lint gcd(lint a, lint b) { while (b) { lint c = a; a = b; b = c % b; } return a; } inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; } bool isprime(lint n) { if (n == 1)return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0)return false; } return true; } template<typename T> T mypow(T a, lint b) { if (!b)return T(1); if (b & 1)return mypow(a, b - 1) * a; T memo = mypow(a, b >> 1); return memo * memo; } lint modpow(lint a, lint b, lint m) { if (!b)return 1; if (b & 1)return modpow(a, b - 1, m) * a % m; lint memo = modpow(a, b >> 1, m); return memo * memo % m; } template<typename T> void printArray(std::vector<T>& vec) { rep(i, vec.size() - 1)std::cout << vec[i] << " "; std::cout << vec.back() << std::endl; } template<typename T> void printArray(T l, T r) { T rprev = r; rprev--; for (T i = l; i != rprev; i++) { std::cout << *i << " "; } std::cout << *rprev << std::endl; } #line 3 "/Users/kaage/Desktop/ProgrammingWorkspace/library/data-structure/BIT.hpp" class BIT { int n; std::vector<lint> bit; public: BIT(unsigned int n) :n(n) { bit.resize(n + 1, 0); } void add(int a, lint x) { while (a <= n) { bit[a] += x; a += a & -a; } } lint query(int a) { lint cnt = 0; while (a > 0) { cnt += bit[a]; a -= a & -a; } return cnt; } void clear() { bit.assign(n + 1, 0); } unsigned int lower_bound(int x){ int p=0,k=1; while(k*2<=n)k*=2; while(k>0){ if(p+k<=n&&bit[p+k]<x){ x-=bit[p+k]; p+=k; } k/=2; } return p+1; } unsigned int upper_bound(int x){ int p=0,k=1; while(k*2<=n)k*=2; while(k>0){ if(p+k<=n&&bit[p+k]<=x){ x-=bit[p+k]; p+=k; } k/=2; } return p+1; } }; #line 3 "main.cpp" int N,Q; int type[500010],v[500010]; lint t[500010],l[500010]; int ans[500010]; std::vector<std::pair<int,lint>> vec[200010],children[200010],comped[200010]; std::vector<std::pair<std::pair<lint,int>,std::pair<int,lint>>> queries[200010]; LP newpar[200010],repr[200010]; bool used[200010]; std::set<int> verset; void dfs(int node){ used[node]=true; for(const auto& i:vec[node]){ if(!used[i.first]){ children[node].emplace_back(i); dfs(i.first); } } } void compress(int node,int par,lint dist){ used[node]=true; bool use=verset.find(node)!=verset.end(); newpar[node]={par,dist}; if(use){ comped[par].emplace_back(node,dist); repr[node]={node,0}; } else repr[node]=newpar[node]; for(const auto& i:children[node]){ if(!used[i.first]){ if(use)compress(i.first,node,i.second); else compress(i.first,par,dist+i.second); } } } int main(){ scanf("%d %d",&N,&Q); rep(i,N-1){ int a,b; lint c; scanf("%d %d %lld",&a,&b,&c); vec[a].emplace_back(b,c); vec[b].emplace_back(a,c); } rep(i,Q)scanf("%d %d %lld %lld",type+i,v+i,t+i,l+i); dfs(1); std::vector<lint> cords; std::queue<std::pair<std::pair<int,lint>,int>> que; BIT bit(2*Q); int B=sqrt(Q); for(int i=0;i<Q;i+=B){ verset.clear(); verset.insert(1); for(int j=i;j<std::min(Q,i+B);j++){ if(type[j]==1)verset.insert(v[j]); } memset(used,false,sizeof(used)); REP(j,N){ comped[j].clear(); queries[j].clear(); } compress(1,0,0); rep(j,i){ if(type[j]==0&&l[j]-repr[v[j]].second>=0){ queries[repr[v[j]].first].push_back({{t[j]+repr[v[j]].second,0},{0,l[j]-repr[v[j]].second}}); } } for(int j=i;j<std::min(Q,i+B);j++){ if(type[j]==1){ que.push({{v[j],0},0}); while(!que.empty()){ auto p=que.front(); que.pop(); queries[p.first.first].push_back({{t[j]-p.first.second,1},{j,p.first.second}}); for(const auto& k:comped[p.first.first]){ if(k.first!=p.second&&p.first.second+k.second<=t[j]){ que.push({{k.first,p.first.second+k.second},p.first.first}); } } } } } REP(j,N){ if(verset.find(j)!=verset.end()){ std::sort(all(queries[j])); cords.clear(); for(const auto& k:queries[j])cords.emplace_back(k.second.second); std::sort(all(cords)); cords.erase(std::unique(all(cords)),cords.end()); for(auto& k:queries[j])k.second.second=std::lower_bound(all(cords),k.second.second)-cords.begin()+1; for(const auto& k:queries[j]){ if(k.first.second==0)bit.add(k.second.second,1); else { ans[k.second.first]+=bit.query(cords.size()+1); if(k.second.second!=1)ans[k.second.first]-=bit.query(k.second.second-1); } } for(const auto& k:queries[j]){ if(k.first.second==0)bit.add(k.second.second,-1); } queries[j].clear(); } } for(int j=std::min(Q,i+B)-1;j>=i;j--){ if(type[j]==0){ int node=v[j]; lint time=t[j]; while(time-t[j]<=l[j]){ for(const auto& k:queries[node]){ if(time<=k.first.first)ans[k.first.second]++; } if(node==1)break; time+=newpar[node].second; node=newpar[node].first; } } else queries[v[j]].push_back({{t[j],j},{0,0}}); } } rep(i,Q){ if(type[i]==1)printf("%d\n",ans[i]); } }