Submission #712089

#TimeUsernameProblemLanguageResultExecution timeMemory
712089PherokungLightning Rod (NOI18_lightningrod)C++14
66 / 100
1608 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define MAXN 10000005 #define F first #define S second #define int long long int n,x[MAXN],y[MAXN],l[MAXN],r[MAXN],rod[MAXN],ans=0; vector<pair<int,int> > v; deque<int> dq; bool oper(pair<int,int> i,pair<int,int> j){ return i.F > j.F; } main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&x[i],&y[i]); v.push_back({y[i],i}); } for(int i=1;i<=n;i++){ while(!dq.empty()){ int p = dq.front(); if(y[i] - x[i] >= y[p] - x[p]){ r[p] = i; dq.pop_front(); } else break; } dq.push_front(i); } while(!dq.empty()){ r[dq.front()] = n+1; dq.pop_front(); } for(int i=n;i>=1;i--){ while(!dq.empty()){ int p = dq.front(); if(y[i] + x[i] >= y[p] + x[p]){ l[p] = i; dq.pop_front(); } else break; } dq.push_front(i); } while(!dq.empty()){ l[dq.front()] = 0; dq.pop_front(); } sort(v.begin(),v.end(),oper); for(auto tw : v){ int i = tw.S; if(!rod[i] && !rod[l[i]] && !rod[r[i]]){ ans++; } rod[i] = 1; } printf("%d",ans); }

Compilation message (stderr)

lightningrod.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main(){
      | ^~~~
lightningrod.cpp: In function 'int main()':
lightningrod.cpp:15:10: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   15 |  scanf("%d",&n);
      |         ~^  ~~
      |          |  |
      |          |  long long int*
      |          int*
      |         %lld
lightningrod.cpp:17:11: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   17 |   scanf("%d%d",&x[i],&y[i]);
      |          ~^    ~~~~~
      |           |    |
      |           int* long long int*
      |          %lld
lightningrod.cpp:17:13: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   17 |   scanf("%d%d",&x[i],&y[i]);
      |            ~^        ~~~~~
      |             |        |
      |             int*     long long int*
      |            %lld
lightningrod.cpp:62:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   62 |  printf("%d",ans);
      |          ~^  ~~~
      |           |  |
      |           |  long long int
      |           int
      |          %lld
lightningrod.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
lightningrod.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d%d",&x[i],&y[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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...