Submission #424194

#TimeUsernameProblemLanguageResultExecution timeMemory
424194dualityArranging Tickets (JOI17_arranging_tickets)C++11
0 / 100
1 ms332 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- int N,A[100000],B[100000],C[100000]; int num[200000]; pii order[100000]; int tree[1 << 19],lazy[1 << 19]; int build(int s,int e,int i) { if (s == e) { tree[i] = lazy[i] = 0; return 0; } int mid = (s+e) / 2; build(s,mid,2*i+1),build(mid+1,e,2*i+2); tree[i] = lazy[i] = 0; return 0; } int prop(int s,int e,int i) { tree[i] += lazy[i]; if (s != e) lazy[2*i+1] += lazy[i],lazy[2*i+2] += lazy[i]; lazy[i] = 0; return 0; } int update(int s,int e,int as,int ae,int i,int num) { prop(s,e,i); if ((s > ae) || (e < as)) return 0; else if ((s >= as) && (e <= ae)) { lazy[i] += num; prop(s,e,i); return 0; } int mid = (s+e) / 2; update(s,mid,as,ae,2*i+1,num),update(mid+1,e,as,ae,2*i+2,num); tree[i] = max(tree[2*i+1],tree[2*i+2]); return 0; } int query(int s,int e,int qs,int qe,int i) { prop(s,e,i); if ((s > qe) || (e < qs)) return -1e9; else if ((s >= qs) && (e <= qe)) return tree[i]; int mid = (s+e) / 2; return max(query(s,mid,qs,qe,2*i+1),query(mid+1,e,qs,qe,2*i+2)); } int main() { int i; int M; LLI ans = 0; scanf("%d %d",&N,&M); for (i = 0; i < M; i++) { scanf("%d %d %d",&A[i],&B[i],&C[i]); if (!(C[i] & 1)) ans += C[i]/2,i--,M--; else { if (A[i] > B[i]) swap(A[i],B[i]); } } int j; int ans2 = 1e9; build(0,N-1,0); for (j = 0; j < M; j++) { update(0,N-1,A[j],B[j]-1,0,-1); order[j] = mp(B[j],j); } int a = M; sort(order,order+M); for (j = 0; j < M; j++) { int u = order[j].second; if (query(0,N-1,A[u],B[u]-1,0) < -1) update(0,N-1,A[u],B[u]-1,0,2),a--; } ans2 = min(ans2,a); printf("%lld\n",ans+ans2); return 0; }

Compilation message (stderr)

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:105:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
arranging_tickets.cpp:107:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         scanf("%d %d %d",&A[i],&B[i],&C[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...